home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume26 / veos-2.0 / part06 < prev    next >
Encoding:
Text File  |  1993-04-25  |  82.9 KB  |  3,040 lines

  1. Newsgroups: comp.sources.unix
  2. From: voodoo@hitl.washington.edu (Geoffery Coco)
  3. Subject: v26i189: veos-2.0 - The Virtual Environment Operating Shell, V2.0, Part06/16
  4. Sender: unix-sources-moderator@vix.com
  5. Approved: paul@vix.com
  6.  
  7. Submitted-By: voodoo@hitl.washington.edu (Geoffery Coco)
  8. Posting-Number: Volume 26, Issue 189
  9. Archive-Name: veos-2.0/part06
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 6 (of 16)."
  18. # Contents:  src/utils/xv_utils.c src/xlisp/xcore/c/unixstuff.c
  19. #   src/xlisp/xcore/c/xlfio.c src/xlisp/xcore/c/xlisp.h
  20. #   src/xlisp/xcore/c/xlmath.c src/xlisp/xcore/c/xlstruct.c
  21. # Wrapped by vixie@efficacy.home.vix.com on Sun Apr 25 23:10:37 1993
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'src/utils/xv_utils.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'src/utils/xv_utils.c'\"
  25. else
  26. echo shar: Extracting \"'src/utils/xv_utils.c'\" \(13040 characters\)
  27. sed "s/^X//" >'src/utils/xv_utils.c' <<'END_OF_FILE'
  28. X/****************************************************************************************
  29. X *                                            *
  30. X * file: xv_utils.c                                    *
  31. X *                                            *
  32. X * Sundry lisp utils for the veos project                        *
  33. X *                                            *
  34. X * creation: March 28, 1991                                *
  35. X *                                            *
  36. X *                                            *
  37. X * Includes utilities by:                                *
  38. X *                                            *
  39. X *    Geoff Coco                                    *
  40. X *    Dav Lion                                    *
  41. X *    Andy McDonald                                    *
  42. X *    Fran Taylor                                    *
  43. X *                                            *
  44. X ****************************************************************************************/
  45. X
  46. X/****************************************************************************************
  47. X * Copyright (C) 1992  Human Interface Technology Lab, Seattle                *
  48. X ****************************************************************************************/
  49. X
  50. X#include "xlisp.h"
  51. X#include "world.h"
  52. X#include <math.h>
  53. X#include <sys/time.h>
  54. X
  55. Xextern LVAL    true;
  56. X
  57. Xtypedef float     TMatrix[4][4];
  58. Xtypedef float     TTriple[3];
  59. Xtypedef float     TVector[4];
  60. X
  61. XLVAL ReverseList();
  62. Xboolean IsTripleElt();
  63. X
  64. X
  65. X/****************************************************************************************/
  66. XLVAL read_time ()
  67. X{
  68. X  struct timeval t;
  69. X  double          now, diff;
  70. X  static double then = 0.0;
  71. X  int            err;
  72. X
  73. X  err = gettimeofday( &t, 0);
  74. X/*
  75. X  fprintf( stderr, "%d %d\n", t.tv_sec, t.tv_usec);
  76. X*/
  77. X  if( err == -1)
  78. X    xlerror( "read-time: timer barfed");
  79. X  else
  80. X    {
  81. X      now = (double)t.tv_sec + (double)t.tv_usec / 1000000.0;
  82. X/*
  83. X      fprintf( stderr, "%f %f\n", now, then);
  84. X*/
  85. X      diff = now - then;
  86. X      then = now;
  87. X    }
  88. X  return cvflonum( diff);
  89. X}
  90. X/****************************************************************************************/
  91. X
  92. X
  93. X
  94. X/****************************************************************************************
  95. X *.native_sprintf -- data conversion.                            *
  96. X ****************************************************************************************/
  97. X
  98. XLVAL native_sprintf()
  99. X{
  100. X    str255    sLocal;
  101. X
  102. X    util_sprintf(sLocal);
  103. X
  104. X    return(cvstring(sLocal));
  105. X
  106. X    } /* native_sprintf */
  107. X/****************************************************************************************/
  108. X
  109. X
  110. X/****************************************************************************************
  111. X *.native_printf -- data conversion.                            *
  112. X ****************************************************************************************/
  113. X
  114. XLVAL native_printf()
  115. X{
  116. X    str255    sLocal;
  117. X
  118. X    util_sprintf(sLocal);
  119. X    fprintf(stderr, "%s\n", sLocal);
  120. X
  121. X    return(true);
  122. X
  123. X    } /* native_printf */
  124. X/****************************************************************************************/
  125. X
  126. X
  127. X
  128. X/****************************************************************************************
  129. X *.native_printf1 -- data conversion.                            *
  130. X ****************************************************************************************/
  131. X
  132. XLVAL native_printf1()
  133. X{
  134. X    str255    sLocal;
  135. X
  136. X    util_sprintf(sLocal);
  137. X    fprintf(stderr, "%s", sLocal);
  138. X
  139. X    return(true);
  140. X
  141. X    } /* native_printf1 */
  142. X/****************************************************************************************/
  143. X
  144. X
  145. X/****************************************************************************************/
  146. XTVeosErr util_sprintf(sDest)
  147. X    char    *sDest;
  148. X{
  149. X    LVAL    pXElt;
  150. X    str63    sZoot;
  151. X
  152. X    sDest[0] = '\0';
  153. X
  154. X    while (moreargs()) {
  155. X
  156. X    pXElt = xlgetarg();
  157. X
  158. X    if (!null(pXElt)) {
  159. X
  160. X        switch (ntype(pXElt)) {
  161. X
  162. X        case FIXNUM:
  163. X        sprintf(sZoot, "%d", getfixnum(pXElt));
  164. X        strcat(sDest, sZoot);
  165. X        break;
  166. X        
  167. X        case FLONUM:
  168. X        sprintf(sZoot, "%.2f", getflonum(pXElt));
  169. X        strcat(sDest, sZoot);
  170. X        break;
  171. X        
  172. X        case STRING:
  173. X        strcat(sDest, (char *) getstring(pXElt));
  174. X        break;
  175. X
  176. X        default:
  177. X        break;
  178. X        }
  179. X        }
  180. X    }
  181. X
  182. X    return(VEOS_SUCCESS);
  183. X
  184. X    } /* util_sprintf */
  185. X/****************************************************************************************/
  186. X
  187. X
  188. X
  189. X
  190. X/****************************************************************************************
  191. X *.native_sscanf -- data conversion.                            *
  192. X ****************************************************************************************/
  193. X
  194. XLVAL native_sscanf()
  195. X{
  196. X    LVAL    pData;
  197. X    LVAL    pList, pXElt;
  198. X    char    *pDataFinger;
  199. X
  200. X    xlsave1(pList);
  201. X    xlsave1(pXElt);
  202. X
  203. X    pData = xlgastring();
  204. X    xllastarg();
  205. X
  206. X    pDataFinger = (char *) getstring(pData);
  207. X    while (pDataFinger) {
  208. X
  209. X    /** skip white space **/
  210. X
  211. X    while (pDataFinger[0] == ' ')
  212. X        pDataFinger ++;
  213. X
  214. X    if (pDataFinger[0] == '\0')
  215. X        break;
  216. X
  217. X    /** StrToXElt() looks for ' ' or '\0' as delimiter **/
  218. X
  219. X    StrToXElt(pDataFinger, &pXElt);
  220. X    pList = cons(pXElt, pList);
  221. X
  222. X    pDataFinger = strchr(pDataFinger, ' ');
  223. X    }
  224. X
  225. X    pList = ReverseList(pList);
  226. X    
  227. X    xlpopn(2);
  228. X
  229. X    return(pList);
  230. X
  231. X    } /* native_sscanf */
  232. X/****************************************************************************************/
  233. X
  234. X
  235. X
  236. X
  237. X/****************************************************************************************/
  238. XTVeosErr XVUtils_LoadPrims()
  239. X{
  240. X    Xform_LoadPrims();
  241. X
  242. X#define UTIL_LOAD
  243. X#include "xv_utils.h"
  244. X#undef UTIL_LOAD
  245. X
  246. X    }
  247. X/****************************************************************************************/
  248. X
  249. X
  250. X
  251. X
  252. X/****************************************************************************************
  253. X * StrToXElt                                         */
  254. X
  255. XTVeosErr StrToXElt(sData, hXElt)
  256. X    char        *sData;
  257. X    LVAL        *hXElt;
  258. X{
  259. X    TVeosErr         iErr;
  260. X    char        *pFinger, cSave;
  261. X    int            iDots, iChars, iDigits;
  262. X    int            iType;
  263. X    LVAL        pXElt;
  264. X    float        fVal;
  265. X    int            iVal;
  266. X
  267. X    iErr = VEOS_SUCCESS;
  268. X    iType = FREE;
  269. X    iDigits = iDots = iChars = 0;
  270. X
  271. X    xlsave1(pXElt);
  272. X
  273. X    pFinger = sData;
  274. X
  275. X    /** minus not necessarily a character **/
  276. X
  277. X    if (pFinger[0] == '-')
  278. X    pFinger ++;
  279. X
  280. X
  281. X    while (TRUE) {
  282. X
  283. X    if (pFinger[0] == ' ' || pFinger[0] == '\0') {
  284. X        break;
  285. X        }
  286. X
  287. X    if (isdigit(pFinger[0]))
  288. X        iDigits ++;
  289. X    else if (pFinger[0] == '.')
  290. X        iDots ++;
  291. X    else 
  292. X        iChars ++;
  293. X    
  294. X    pFinger ++;
  295. X    }
  296. X
  297. X    cSave = pFinger[0];
  298. X    pFinger[0] = '\0';
  299. X
  300. X    if (iChars > 0 || iDots > 1)
  301. X    pXElt = cvstring(sData);
  302. X
  303. X    else {
  304. X    if (iDots == 0) {
  305. X        sscanf(sData, "%d", &iVal);
  306. X        pXElt = cvfixnum(iVal);
  307. X        }
  308. X    else {
  309. X        sscanf(sData, "%f", &fVal);
  310. X        pXElt = cvflonum(fVal);
  311. X        }
  312. X    }
  313. X
  314. X    pFinger[0] = cSave;
  315. X
  316. X    *hXElt = pXElt;
  317. X
  318. X    xlpop();
  319. X
  320. X    return(iErr);
  321. X
  322. X    } /* StrToXElt */
  323. X/****************************************************************************************/
  324. X
  325. X
  326. X
  327. X/****************************************************************************************/
  328. XLVAL ReverseList(pList)
  329. X    LVAL    pList;
  330. X{
  331. X    LVAL    pSave, pXElt; 
  332. X    
  333. X    xlsave1(pSave); 
  334. X    xlsave1(pXElt); 
  335. X
  336. X    while (!null(pList)) { 
  337. X    pSave = cdr(pList); 
  338. X    rplacd(pList, pXElt); 
  339. X    pXElt = pList; 
  340. X    pList = pSave; 
  341. X    } 
  342. X
  343. X    xlpopn(2); 
  344. X
  345. X    return(pXElt);
  346. X    
  347. X    } /* Native_ReverseList */
  348. X/****************************************************************************************/
  349. X
  350. X
  351. X
  352. X/****************************************************************************************/
  353. Xboolean    IsQuatElt(pXElt)
  354. X    LVAL    pXElt;
  355. X{
  356. X    return(vectorp(pXElt) &&
  357. X       getsz(pXElt) == 2 &&
  358. X       floatp(getelement(pXElt, 0)) &&
  359. X       IsTripleElt(getelement(pXElt, 1)));
  360. X
  361. X    } /* IsQuatElt */
  362. X/****************************************************************************************/
  363. X
  364. X
  365. X/****************************************************************************************/
  366. Xboolean    IsMatrixElt(pXElt)
  367. X    LVAL    pXElt;
  368. X{
  369. X    return(vectorp(pXElt) && getsz(pXElt) == 16);
  370. X
  371. X    } /* IsMatrixElt */
  372. X/****************************************************************************************/
  373. X
  374. X
  375. X/****************************************************************************************/
  376. Xvoid XVect2Mat(pXElt, pMat)
  377. X    LVAL    pXElt;
  378. X    TMatrix    pMat;
  379. X{
  380. X    int        iEltIndex;
  381. X
  382. X    /** assume sanity is checked **/
  383. X    for (iEltIndex = 0; iEltIndex < 16; iEltIndex ++)
  384. X    pMat[iEltIndex / 4][iEltIndex % 4] = getflonum(getelement(pXElt, iEltIndex));
  385. X
  386. X    } /* XVect2Mat */
  387. X/****************************************************************************************/
  388. X
  389. X
  390. X/****************************************************************************************/
  391. XLVAL Mat2XVect(pMat)
  392. X    TMatrix    pMat;
  393. X{
  394. X    LVAL    pXElt;
  395. X    int        iEltIndex;
  396. X
  397. X    xlsave1(pXElt);
  398. X
  399. X    /** assume sanity is checked **/
  400. X    pXElt = newvector(16);
  401. X
  402. X    for (iEltIndex = 0; iEltIndex < 16; iEltIndex ++)
  403. X    setelement(pXElt, iEltIndex, cvflonum(pMat[iEltIndex / 4][iEltIndex % 4]));
  404. X
  405. X    xlpop();
  406. X
  407. X    return(pXElt);
  408. X
  409. X    } /* Mat2XVect */
  410. X/****************************************************************************************/
  411. X
  412. X
  413. X/****************************************************************************************/
  414. Xboolean    IsTripleElt(pXElt)
  415. X    LVAL    pXElt;
  416. X{
  417. X    return(vectorp(pXElt) && getsz(pXElt) == 3);
  418. X
  419. X    } /* IsTripleElt */
  420. X/****************************************************************************************/
  421. X
  422. X
  423. X/****************************************************************************************/
  424. Xvoid XVect2Tri(pXElt, pTri)
  425. X    LVAL    pXElt;
  426. X    TTriple    pTri;
  427. X{
  428. X    /** assume sanity is checked **/
  429. X
  430. X    pTri[0] = getflonum(getelement(pXElt, 0));
  431. X    pTri[1] = getflonum(getelement(pXElt, 1));
  432. X    pTri[2] = getflonum(getelement(pXElt, 2));
  433. X
  434. X    } /* XVect2Tri */
  435. X/****************************************************************************************/
  436. X
  437. X
  438. X/****************************************************************************************/
  439. XLVAL Tri2XVect(pTri)
  440. X    TTriple    pTri;
  441. X{
  442. X    LVAL    pXElt;
  443. X
  444. X    xlsave1(pXElt);
  445. X
  446. X    /** assume sanity is checked **/
  447. X    pXElt = newvector(3);
  448. X
  449. X    setelement(pXElt, 0, cvflonum(pTri[0]));
  450. X    setelement(pXElt, 1, cvflonum(pTri[1]));
  451. X    setelement(pXElt, 2, cvflonum(pTri[2]));
  452. X
  453. X    xlpop();
  454. X
  455. X    return(pXElt);
  456. X
  457. X    } /* Tri2XVect */
  458. X/****************************************************************************************/
  459. X
  460. X
  461. X/****************************************************************************************/
  462. Xvoid XVect2Quat(pXElt, pVect)
  463. X    LVAL    pXElt;
  464. X    TVector    pVect;
  465. X{
  466. X    LVAL    pTri;
  467. X
  468. X    /** assume sanity is checked **/
  469. X
  470. X    pVect[0] = getflonum(getelement(pXElt, 0));
  471. X
  472. X    pTri = getelement(pXElt, 1);
  473. X    pVect[1] = getflonum(getelement(pTri, 0));
  474. X    pVect[2] = getflonum(getelement(pTri, 1));
  475. X    pVect[3] = getflonum(getelement(pTri, 2));
  476. X    
  477. X    } /* XVect2Quat */
  478. X/****************************************************************************************/
  479. X
  480. X
  481. X/****************************************************************************************/
  482. XLVAL Quat2XVect(pVect)
  483. X    TVector    pVect;
  484. X{
  485. X    LVAL    pXElt, pMid;
  486. X
  487. X    /** assume sanity is checked **/
  488. X
  489. X    xlsave1(pXElt);
  490. X    xlsave1(pMid);
  491. X
  492. X    pMid = newvector(3);
  493. X
  494. X    setelement(pMid, 0, cvflonum(pVect[1]));
  495. X    setelement(pMid, 1, cvflonum(pVect[2]));
  496. X    setelement(pMid, 2, cvflonum(pVect[3]));
  497. X
  498. X    pXElt = newvector(2);
  499. X           
  500. X    setelement(pXElt, 0, cvflonum(pVect[0]));
  501. X    setelement(pXElt, 1, pMid);
  502. X
  503. X    xlpopn(2);
  504. X
  505. X    return(pXElt);
  506. X
  507. X    } /* Quat2XVect */
  508. X/****************************************************************************************/
  509. X
  510. X
  511. X
  512. X/****************************************************************************************/
  513. Xvoid
  514. XLispMat2Mat(lMat, pMat)
  515. X    LVAL    lMat;
  516. X    float    pMat[4][4];
  517. X{    
  518. X    pMat[0][0] = getflonum(getelement(lMat, 0));
  519. X    pMat[0][1] = getflonum(getelement(lMat, 1));
  520. X    pMat[0][2] = getflonum(getelement(lMat, 2));
  521. X    pMat[0][3] = getflonum(getelement(lMat, 3));
  522. X
  523. X    pMat[1][0] = getflonum(getelement(lMat, 4));
  524. X    pMat[1][1] = getflonum(getelement(lMat, 5));
  525. X    pMat[1][2] = getflonum(getelement(lMat, 6));
  526. X    pMat[1][3] = getflonum(getelement(lMat, 7));
  527. X
  528. X    pMat[2][0] = getflonum(getelement(lMat, 8));
  529. X    pMat[2][1] = getflonum(getelement(lMat, 9));
  530. X    pMat[2][2] = getflonum(getelement(lMat, 10));
  531. X    pMat[2][3] = getflonum(getelement(lMat, 11));
  532. X
  533. X    pMat[3][0] = getflonum(getelement(lMat, 12));
  534. X    pMat[3][1] = getflonum(getelement(lMat, 13));
  535. X    pMat[3][2] = getflonum(getelement(lMat, 14));
  536. X    pMat[3][3] = getflonum(getelement(lMat, 15));
  537. X              
  538. X    
  539. X    }/*LispMat2Mat*/
  540. X/****************************************************************************************/
  541. X
  542. X
  543. X/****************************************************************************************/
  544. Xvoid
  545. XMat2LispMat(pMat, lMat)
  546. X     float    pMat[4][4];
  547. X     LVAL    lMat;
  548. X{
  549. X
  550. X    stuff_flonum(lMat, 0,     pMat[0][0]);
  551. X    stuff_flonum(lMat, 1,     pMat[0][1]);
  552. X    stuff_flonum(lMat, 2,     pMat[0][2]);
  553. X    stuff_flonum(lMat, 3,     pMat[0][3]);
  554. X    
  555. X    stuff_flonum(lMat, 4,     pMat[1][0]);
  556. X    stuff_flonum(lMat, 5,     pMat[1][1]);
  557. X    stuff_flonum(lMat, 6,     pMat[1][2]);
  558. X    stuff_flonum(lMat, 7,     pMat[1][3]);
  559. X    
  560. X    stuff_flonum(lMat, 8,     pMat[2][0]);
  561. X    stuff_flonum(lMat, 9,     pMat[2][1]);
  562. X    stuff_flonum(lMat, 10,     pMat[2][2]);
  563. X    stuff_flonum(lMat, 11,     pMat[2][3]);
  564. X    
  565. X    stuff_flonum(lMat, 12,     pMat[3][0]);
  566. X    stuff_flonum(lMat, 13,     pMat[3][1]);
  567. X    stuff_flonum(lMat, 14,     pMat[3][2]);
  568. X    stuff_flonum(lMat, 15,     pMat[3][3]);
  569. X
  570. X    }/*Mat2LispMat*/
  571. X/****************************************************************************************/
  572. X
  573. END_OF_FILE
  574. if test 13040 -ne `wc -c <'src/utils/xv_utils.c'`; then
  575.     echo shar: \"'src/utils/xv_utils.c'\" unpacked with wrong size!
  576. fi
  577. # end of 'src/utils/xv_utils.c'
  578. fi
  579. if test -f 'src/xlisp/xcore/c/unixstuff.c' -a "${1}" != "-c" ; then 
  580.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/unixstuff.c'\"
  581. else
  582. echo shar: Extracting \"'src/xlisp/xcore/c/unixstuff.c'\" \(14087 characters\)
  583. sed "s/^X//" >'src/xlisp/xcore/c/unixstuff.c' <<'END_OF_FILE'
  584. X/* -*-C-*-
  585. X********************************************************************************
  586. X*
  587. X* File:         unixstuff.c
  588. X* RCS:          $Header: unixstuff.c,v 1.3 89/11/25 05:12:16 mayer Exp $
  589. X* Description:  UNIX-Specific interfaces for XLISP
  590. X* Author:       David Michael Betz; Niels Mayer
  591. X* Created:      
  592. X* Modified:     Sat Nov 25 05:12:04 1989 (Niels Mayer) mayer@hplnpm
  593. X* Language:     C
  594. X* Package:      N/A
  595. X* Status:       X11r4 contrib tape release
  596. X*
  597. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  598. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  599. X*
  600. X* Permission to use, copy, modify, distribute, and sell this software and its
  601. X* documentation for any purpose is hereby granted without fee, provided that
  602. X* the above copyright notice appear in all copies and that both that
  603. X* copyright notice and this permission notice appear in supporting
  604. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  605. X* used in advertising or publicity pertaining to distribution of the software
  606. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  607. X* make no representations about the suitability of this software for any
  608. X* purpose. It is provided "as is" without express or implied warranty.
  609. X*
  610. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  611. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  612. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  613. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  614. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  615. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  616. X* PERFORMANCE OF THIS SOFTWARE.
  617. X*
  618. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  619. X* 
  620. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  621. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  622. X*
  623. X********************************************************************************
  624. X*/
  625. Xstatic char rcs_identity[] = "@(#)$Header: unixstuff.c,v 1.3 89/11/25 05:12:16 mayer Exp $";
  626. X
  627. X
  628. X#include "xlisp.h"
  629. X
  630. X/******************************************************************************
  631. X * Prim_POPEN - start a process and open a pipe for read/write 
  632. X * (code stolen from xlfio.c:xopen())
  633. X *
  634. X * syntax: (popen <command line> :direction <direction>)
  635. X *                <command line> is a string to be sent to the subshell (sh).
  636. X *                <direction> is either :input (to read from the pipe) or
  637. X *                                      :output (to write to the pipe).
  638. X *                                      (:input is the default)
  639. X *
  640. X * Popen returns a stream, or NIL if files or processes couldn't be created.
  641. X * The  success  of  the  command  execution  can be checked by examining the 
  642. X * return value of pclose. 
  643. X *
  644. X * Added to XLISP by Niels Mayer
  645. X ******************************************************************************/
  646. XLVAL Prim_POPEN()
  647. X{
  648. X  extern LVAL k_direction, k_input, k_output;
  649. X  char *name,*mode;
  650. X  FILE *fp;
  651. X  LVAL dir;
  652. X
  653. X  /* get the process name and direction */
  654. X  name = (char *) getstring(xlgastring());
  655. X  if (!xlgetkeyarg(k_direction, &dir))
  656. X    dir = k_input;
  657. X  
  658. X  /* get the mode */
  659. X  if (dir == k_input)
  660. X    mode = "r";
  661. X  else if (dir == k_output)
  662. X    mode = "w";
  663. X  else
  664. X    xlerror("bad direction",dir);
  665. X  
  666. X  /* try to open the file */
  667. X  return ((fp = popen(name,mode)) ? cvfile(fp) : NIL);
  668. X}
  669. X
  670. X
  671. X/******************************************************************************
  672. X * Prim_PCLOSE - close a pipe opened by Prim_POPEN().
  673. X * (code stolen from xlfio.c:xclose())
  674. X *
  675. X * syntax: (pclose <stream>)
  676. X *                  <stream> is a stream created by popen.
  677. X * returns T if the command executed successfully, otherwise, 
  678. X * returns the exit status of the opened command.
  679. X *
  680. X * Added to XLISP by Niels Mayer
  681. X ******************************************************************************/
  682. XLVAL Prim_PCLOSE()
  683. X{
  684. X  extern LVAL true;
  685. X  LVAL fptr;
  686. X  int  result;
  687. X
  688. X  /* get file pointer */
  689. X  fptr = xlgastream();
  690. X  xllastarg();
  691. X
  692. X  /* make sure the file exists */
  693. X  if (getfile(fptr) == NULL)
  694. X    xlfail("file not open");
  695. X
  696. X  /* close the pipe */
  697. X  result = pclose(getfile(fptr));
  698. X
  699. X  if (result == -1)
  700. X    xlfail("<stream> has not been opened with popen");
  701. X    
  702. X  setfile(fptr,NULL);
  703. X
  704. X  /* return T if success (exit status 0), else return exit status */
  705. X  return (result ? cvfixnum(result) : true);
  706. X}
  707. X
  708. X
  709. X/******************************************************************************
  710. X * Prim_SYSTEM - run a process, sending output (if any) to stdout/stderr
  711. X *
  712. X * syntax: (system <command line>)
  713. X *                 <command line> is a string to be sent to the subshell (sh).
  714. X *
  715. X * Returns T if the command executed succesfully, otherwise returns the 
  716. X * integer shell exit status for the command.
  717. X *
  718. X * Added to XLISP by Niels Mayer
  719. X ******************************************************************************/
  720. XLVAL Prim_SYSTEM()
  721. X{
  722. X  extern LVAL true;
  723. X  extern int sys_nerr;
  724. X  extern char *sys_errlist[];
  725. X  extern int errno;
  726. X  LVAL command;
  727. X  int  result;
  728. X  char temptext[1024];
  729. X
  730. X  /* get shell command */
  731. X  command = xlgastring();
  732. X  xllastarg();
  733. X  
  734. X  /* run the process */
  735. X  result = system((char *) getstring(command));
  736. X
  737. X  if (result == -1) {        /* if a system error has occured */
  738. X    if (errno < sys_nerr)
  739. X      (void) sprintf(temptext, "Error in system(3S): %s\n", sys_errlist[errno]);
  740. X    else
  741. X      (void) strcpy(temptext, "Error in system(3S): unknown error\n");
  742. X    xlfail(temptext);
  743. X  }
  744. X
  745. X  /* return T if success (exit status 0), else return exit status */
  746. X  return (result ? cvfixnum(result) : true);
  747. X}
  748. X
  749. X
  750. X/******************************************************************************
  751. X * (FSCANF-FIXNUM <stream> <scanf-format>)
  752. X * This routine calls fscanf(3s) on a <stream> that was previously openend
  753. X * via open or popen. It will not work on an USTREAM.
  754. X * <scanf-format> is a format string containing a single conversion
  755. X * directive that will result in an integer valued conversion.
  756. X * %d, %u, %o, %x, %ld, %lu, %lo and %lx style conversions 
  757. X * are acceptable for this routine.
  758. X * WARNING: specifying a <scanf-format> that will result in the conversion
  759. X * of a result larger than sizeof(long) will result in corrupted memory and
  760. X * core dumps. 
  761. X * 
  762. X * This routine will return an FIXNUM if fscanf() returns 1 (i.e. if
  763. X * the one expected conversion has succeeded. It will return NIL if the
  764. X * conversion wasn't successful, or if EOF was reached.
  765. X ******************************************************************************/
  766. XLVAL Prim_FSCANF_FIXNUM()
  767. X{
  768. X  LVAL  lval_stream;
  769. X  char* fmt;
  770. X  long  result;
  771. X  
  772. X  lval_stream = xlgastream();
  773. X  if (getfile(lval_stream) == NULL)
  774. X    xlerror("File not opened.", lval_stream);
  775. X  fmt = (char *) getstring(xlgastring());
  776. X  xllastarg();
  777. X  
  778. X  result = 0L;            /* clear it out hibits incase short is written */
  779. X  /* if scanf returns result <1 then an error or eof occured. */
  780. X  if (fscanf(getfile(lval_stream), fmt, &result) < 1)
  781. X    return (NIL);
  782. X  else
  783. X    return (cvfixnum((FIXTYPE) result));
  784. X}
  785. X
  786. X
  787. X/******************************************************************************
  788. X * (FSCANF-STRING <stream> <scanf-format>)
  789. X * This routine calls fscanf(3s) on a <stream> that was previously openend
  790. X * via open or popen. It will not work on an USTREAM.
  791. X * <scanf-format> is a format string containing a single conversion
  792. X * directive that will result in a string valued conversion.
  793. X * %s, %c, and %[...] style conversions are acceptable for
  794. X * this routine.
  795. X * WARNING: specifying a <scanf-format> that will result in the conversion
  796. X * of a result larger than 1024 characters will result in corrupted
  797. X * memory and core dumps.
  798. X * 
  799. X * This routine will return a string if fscanf() returns 1 (i.e. if
  800. X * the one expected conversion has succeeded. It will return NIL if the
  801. X * conversion wasn't successful, or if EOF was reached.
  802. X ******************************************************************************/
  803. XLVAL Prim_FSCANF_STRING()
  804. X{
  805. X  LVAL lval_stream;
  806. X  char* fmt;
  807. X  char result[BUFSIZ];
  808. X
  809. X  
  810. X  lval_stream = xlgastream();
  811. X  if (getfile(lval_stream) == NULL)
  812. X    xlerror("File not opened.", lval_stream);
  813. X  fmt = (char *) getstring(xlgastring());
  814. X  xllastarg();
  815. X  
  816. X  result[0] = result[1] = '\0';    /* if the conversion is %c, then fscanf
  817. X                   doesn't null terminate the string,
  818. X                   so do it just incase */
  819. X
  820. X  /* if scanf returns result <1 then an error or eof occured. */
  821. X  if (fscanf(getfile(lval_stream), fmt, result) < 1)
  822. X    return (NIL);
  823. X  else
  824. X    return (cvstring(result));
  825. X}
  826. X
  827. X
  828. X/******************************************************************************
  829. X * (FSCANF-FLONUM <stream> <scanf-format>)
  830. X * This routine calls fscanf(3s) on a <stream> that was previously openend
  831. X * via open or popen. It will not work on an USTREAM.
  832. X * <scanf-format> is a format string containing a single conversion
  833. X * directive that will result in an FLONUM valued conversion.
  834. X * %e %f or %g are valid conversion specifiers for this routine.
  835. X *
  836. X * WARNING: specifying a <scanf-format> that will result in the conversion
  837. X * of a result larger than sizeof(float) will result in corrupted memory and
  838. X * core dumps. 
  839. X * 
  840. X * This routine will return a FLONUM if fscanf() returns 1 (i.e. if
  841. X * the one expected conversion has succeeded. It will return NIL if the
  842. X * conversion wasn't successful, or if EOF was reached.
  843. X ******************************************************************************/
  844. XLVAL Prim_FSCANF_FLONUM()
  845. X{
  846. X  LVAL lval_stream;
  847. X  char* fmt;
  848. X  FILE * fp;
  849. X  float result;
  850. X  
  851. X  lval_stream = xlgastream();
  852. X  if (getfile(lval_stream) == NULL)
  853. X    xlerror("File not opened.", lval_stream);
  854. X  fmt = (char *) getstring(xlgastring());
  855. X  xllastarg();
  856. X  
  857. X  /* if scanf returns result <1 then an error or eof occured. */
  858. X  if (fscanf(getfile(lval_stream), fmt, &result) < 1)
  859. X    return (NIL);
  860. X  else
  861. X    return (cvflonum((FLOTYPE) result));
  862. X}
  863. X
  864. X
  865. X/******************************************************************************/
  866. X/******************************************************************************/
  867. X/******************************************************************************/
  868. X/* -- stuff.c  -- operating system specific routines */
  869. X/* -- Written by dbetz for XLISP 2.0 */
  870. X/* -- Copied by EFJohnson from a BIX message */
  871. X/* -- Unix System V */
  872. X
  873. X#define    LBSIZE    200
  874. X
  875. X/* -- external variables */
  876. Xextern    FILE    *tfp;
  877. X
  878. X/* -- local variables */
  879. Xstatic    long    rseed = 1L;
  880. X
  881. Xstatic    char    lbuf[LBSIZE];
  882. Xstatic    int    lindex;
  883. Xstatic    int    lcount;
  884. X
  885. X
  886. X/* -- osinit - initialize */
  887. Xosinit(banner)
  888. Xchar    *banner;
  889. X{
  890. X    printf("%s\n", banner );
  891. X    lindex    = 0;
  892. X    lcount    = 0;
  893. X}
  894. X
  895. X/* -- osfinish - clean up before returning to the operating system */
  896. Xosfinish()
  897. X{
  898. X}
  899. X
  900. X
  901. X/* -- xoserror - print an error message */
  902. Xxoserror(msg)
  903. X
  904. Xchar    *msg;
  905. X
  906. X{
  907. X    printf( "error: %s\n", msg );
  908. X}
  909. X
  910. X
  911. X/* -- osrand - return a random number between 0 and n-1 */
  912. Xint osrand(n)
  913. X
  914. Xint    n;
  915. X
  916. X{
  917. X    long k1;
  918. X
  919. X    /* -- make sure we don't get stuck at zero */
  920. X    if ( rseed == 0L ) rseed = 1L;
  921. X
  922. X    /* -- algorithm taken from Dr Dobbs Journal, Nov. 1985, page 91 */
  923. X    k1 = rseed / 127773L;
  924. X    if ( ( rseed = 16807L * (rseed - k1 * 127773L) -k1 * 2836L) < 0L )
  925. X        rseed += 2147483647L;
  926. X
  927. X    /* -- return a random number between 0 and n-1 */
  928. X    return( (int) (rseed % (long) n ) );
  929. X}
  930. X
  931. X
  932. X
  933. X/* -- osaopen -- open an ascii file */
  934. XFILE    *osaopen( name, mode )
  935. Xchar    *name, *mode;
  936. X{
  937. X    return( fopen( name, mode ) );
  938. X}
  939. X
  940. X
  941. X
  942. X/* -- osbopen -- open a binary file */
  943. XFILE    *osbopen( name, mode )
  944. Xchar    *name, *mode;
  945. X{
  946. X    return( fopen( name, mode ) );
  947. X}
  948. X
  949. X
  950. X/* -- osclose -- close a file */
  951. Xint    osclose( fp )
  952. XFILE    *fp;
  953. X{
  954. X    return( fclose( fp ) );
  955. X}
  956. X
  957. X
  958. X/* -- osagetc - get a character from an ASCII file */
  959. Xint    osagetc( fp )
  960. XFILE    *fp;
  961. X{
  962. X    return( getc(fp) );
  963. X}
  964. X
  965. X/* -- osaputc - put a character to an ASCII file */
  966. Xint    osaputc( ch, fp )
  967. Xint    ch;
  968. XFILE    *fp;
  969. X{
  970. X    return( putc( ch, fp ) );
  971. X}
  972. X
  973. X
  974. X
  975. X/* -- osbgetc - get a character from a binary file */
  976. Xint    osbgetc( fp )
  977. XFILE    *fp;
  978. X{
  979. X    return( getc(fp) );
  980. X}
  981. X
  982. X/* -- osbputc - put a character to a binary file */
  983. Xint    osbputc( ch, fp )
  984. Xint    ch;
  985. XFILE    *fp;
  986. X{
  987. X    return( putc( ch, fp ) );
  988. X}
  989. X
  990. X
  991. X/* -- ostgetc - get a character from the terminal */
  992. Xint    ostgetc()
  993. X{
  994. X    while(--lcount < 0 )
  995. X        {
  996. X        if ( fgets(lbuf,LBSIZE,stdin) == NULL )
  997. X            return( EOF );
  998. X        if ( tfp )
  999. X            fputs( lbuf, tfp );
  1000. X        lcount = strlen( lbuf );
  1001. X        lindex = 0;
  1002. X        }
  1003. X
  1004. X    return( lbuf[lindex++] );
  1005. X}
  1006. X
  1007. X
  1008. X/* -- ostputc - put a character to the terminal */
  1009. Xostputc( ch )
  1010. Xint    ch;
  1011. X{
  1012. X    /* -- check for control characters */
  1013. X    oscheck();
  1014. X    
  1015. X    /* -- output the character */
  1016. X    putchar( ch );
  1017. X
  1018. X    /* -- output the char to the transcript file */
  1019. X    if ( tfp )
  1020. X        osaputc( ch, tfp );
  1021. X}
  1022. X
  1023. X
  1024. X
  1025. X
  1026. X/* -- osflush - flush the terminal input buffer */
  1027. Xosflush()
  1028. X{
  1029. X    lindex = lcount = 0;
  1030. X}
  1031. X
  1032. X
  1033. X/* -- oscheck - check for control characters during execution */
  1034. Xoscheck()
  1035. X{
  1036. X}
  1037. X
  1038. X
  1039. X/* -- ossymbols - enter os-specific symbols */
  1040. Xossymbols()
  1041. X{
  1042. X}
  1043. X
  1044. X/******************************************************************************
  1045. X * xosgetenv - get string from environment
  1046. X * 
  1047. X * syntax: (getenv key)
  1048. X *                <key> is something like TERM to look up in the unix environment.
  1049. X * 
  1050. X * If "<key>=<val> is not found in the environment, xosgetenv returns NIL.
  1051. X * Otherwise, xosgetenv returns a list of strings, one for each ':'-delimited
  1052. X * component of <val>.
  1053. X *
  1054. X * Added to XLISP by Jeff Prothero
  1055. X ******************************************************************************/
  1056. XLVAL envget( key_as_asciz )
  1057. Xchar*        key_as_asciz;
  1058. X{
  1059. X    extern char* getenv();
  1060. X    LVAL result;
  1061. X    char *val_as_asciz = getenv( key_as_asciz );
  1062. X    xlsave1( result );
  1063. X    if (val_as_asciz != NULL) {
  1064. X    do {
  1065. X        char buf[ 1024 ];
  1066. X            char *dst = buf;
  1067. X        while (*val_as_asciz   &&   *val_as_asciz != ':') {
  1068. X        *dst++ = *val_as_asciz++;
  1069. X        }
  1070. X        *dst = '\0';
  1071. X        result = cons( cvstring(buf), result );
  1072. X    } while (*val_as_asciz++);
  1073. X    }
  1074. X    xlpop();
  1075. X    return result;
  1076. X}
  1077. XLVAL xosenvget()
  1078. X{
  1079. X    char *key_as_asciz = (char *) getstring(xlgastring());
  1080. X    xllastarg();
  1081. X    return envget( key_as_asciz );
  1082. X}
  1083. END_OF_FILE
  1084. if test 14087 -ne `wc -c <'src/xlisp/xcore/c/unixstuff.c'`; then
  1085.     echo shar: \"'src/xlisp/xcore/c/unixstuff.c'\" unpacked with wrong size!
  1086. fi
  1087. # end of 'src/xlisp/xcore/c/unixstuff.c'
  1088. fi
  1089. if test -f 'src/xlisp/xcore/c/xlfio.c' -a "${1}" != "-c" ; then 
  1090.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlfio.c'\"
  1091. else
  1092. echo shar: Extracting \"'src/xlisp/xcore/c/xlfio.c'\" \(11944 characters\)
  1093. sed "s/^X//" >'src/xlisp/xcore/c/xlfio.c' <<'END_OF_FILE'
  1094. X/* -*-C-*-
  1095. X********************************************************************************
  1096. X*
  1097. X* File:         xlfio.c
  1098. X* RCS:          $Header: xlfio.c,v 1.4 89/11/25 05:24:44 mayer Exp $
  1099. X* Description:  xlisp file i/o
  1100. X* Author:       David Michael Betz
  1101. X* Created:      
  1102. X* Modified:     Sat Nov 25 05:24:25 1989 (Niels Mayer) mayer@hplnpm
  1103. X* Language:     C
  1104. X* Package:      N/A
  1105. X* Status:       X11r4 contrib tape release
  1106. X*
  1107. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  1108. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  1109. X*
  1110. X* Permission to use, copy, modify, distribute, and sell this software and its
  1111. X* documentation for any purpose is hereby granted without fee, provided that
  1112. X* the above copyright notice appear in all copies and that both that
  1113. X* copyright notice and this permission notice appear in supporting
  1114. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  1115. X* used in advertising or publicity pertaining to distribution of the software
  1116. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  1117. X* make no representations about the suitability of this software for any
  1118. X* purpose. It is provided "as is" without express or implied warranty.
  1119. X*
  1120. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  1121. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  1122. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  1123. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  1124. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  1125. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1126. X* PERFORMANCE OF THIS SOFTWARE.
  1127. X*
  1128. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  1129. X* 
  1130. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  1131. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  1132. X*
  1133. X********************************************************************************
  1134. X*/
  1135. Xstatic char rcs_identity[] = "@(#)$Header: xlfio.c,v 1.4 89/11/25 05:24:44 mayer Exp $";
  1136. X
  1137. X#include "xlisp.h"
  1138. X
  1139. X/* external variables */
  1140. Xextern LVAL k_direction,k_input,k_output;
  1141. Xextern LVAL s_stdin,s_stdout,s_stderr,true;
  1142. Xextern unsigned char buf[];
  1143. Xextern int xlfsize;
  1144. X
  1145. X/* external routines */
  1146. Xextern FILE *osaopen();
  1147. X
  1148. X/* forward declarations */
  1149. XFORWARD LVAL getstroutput();
  1150. XFORWARD LVAL printit();
  1151. XFORWARD LVAL flatsize();
  1152. XFORWARD LVAL openit();
  1153. X
  1154. X/* xread - read an expression */
  1155. XLVAL xread()
  1156. X{
  1157. X    LVAL fptr,eof,rflag,val;
  1158. X
  1159. X    /* get file pointer and eof value */
  1160. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  1161. X    eof = (moreargs() ? xlgetarg() : NIL);
  1162. X    rflag = (moreargs() ? xlgetarg() : NIL);
  1163. X    xllastarg();
  1164. X
  1165. X    /* read an expression */
  1166. X    if (!xlread(fptr,&val,rflag != NIL))
  1167. X    val = eof;
  1168. X
  1169. X    /* return the expression */
  1170. X    return (val);
  1171. X}
  1172. X
  1173. X/* xprint - built-in function 'print' */
  1174. XLVAL xprint()
  1175. X{
  1176. X    return (printit(TRUE,TRUE));
  1177. X}
  1178. X
  1179. X/* xprin1 - built-in function 'prin1' */
  1180. XLVAL xprin1()
  1181. X{
  1182. X    return (printit(TRUE,FALSE));
  1183. X}
  1184. X
  1185. X/* xprinc - built-in function princ */
  1186. XLVAL xprinc()
  1187. X{
  1188. X    return (printit(FALSE,FALSE));
  1189. X}
  1190. X
  1191. X/* xterpri - terminate the current print line */
  1192. XLVAL xterpri()
  1193. X{
  1194. X    LVAL fptr;
  1195. X
  1196. X    /* get file pointer */
  1197. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  1198. X    xllastarg();
  1199. X
  1200. X    /* terminate the print line and return nil */
  1201. X    xlterpri(fptr);
  1202. X    return (NIL);
  1203. X}
  1204. X
  1205. X/* printit - common print function */
  1206. XLOCAL LVAL printit(pflag,tflag)
  1207. X  int pflag,tflag;
  1208. X{
  1209. X    LVAL fptr,val;
  1210. X
  1211. X    /* get expression to print and file pointer */
  1212. X    val = xlgetarg();
  1213. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  1214. X    xllastarg();
  1215. X
  1216. X    /* print the value */
  1217. X    xlprint(fptr,val,pflag);
  1218. X
  1219. X    /* terminate the print line if necessary */
  1220. X    if (tflag)
  1221. X    xlterpri(fptr);
  1222. X
  1223. X    /* return the result */
  1224. X    return (val);
  1225. X}
  1226. X
  1227. X/* xflatsize - compute the size of a printed representation using prin1 */
  1228. XLVAL xflatsize()
  1229. X{
  1230. X    return (flatsize(TRUE));
  1231. X}
  1232. X
  1233. X/* xflatc - compute the size of a printed representation using princ */
  1234. XLVAL xflatc()
  1235. X{
  1236. X    return (flatsize(FALSE));
  1237. X}
  1238. X
  1239. X/* flatsize - compute the size of a printed expression */
  1240. XLOCAL LVAL flatsize(pflag)
  1241. X  int pflag;
  1242. X{
  1243. X    LVAL val;
  1244. X
  1245. X    /* get the expression */
  1246. X    val = xlgetarg();
  1247. X    xllastarg();
  1248. X
  1249. X    /* print the value to compute its size */
  1250. X    xlfsize = 0;
  1251. X    xlprint(NIL,val,pflag);
  1252. X
  1253. X    /* return the length of the expression */
  1254. X    return (cvfixnum((FIXTYPE)xlfsize));
  1255. X}
  1256. X
  1257. X/* xopen - open a file */
  1258. XLVAL xopen()
  1259. X{
  1260. X    char *name,*mode;
  1261. X    FILE *fp;
  1262. X    LVAL dir;
  1263. X
  1264. X    /* get the file name and direction */
  1265. X    name = (char *)getstring(xlgetfname());
  1266. X    if (!xlgetkeyarg(k_direction,&dir))
  1267. X    dir = k_input;
  1268. X
  1269. X    /* get the mode */
  1270. X    if (dir == k_input)
  1271. X    mode = "r";
  1272. X    else if (dir == k_output)
  1273. X    mode = "w";
  1274. X    else
  1275. X    xlerror("bad direction",dir);
  1276. X
  1277. X    /* try to open the file */
  1278. X    return ((fp = osaopen(name,mode)) ? cvfile(fp) : NIL);
  1279. X}
  1280. X
  1281. X/* xclose - close a file */
  1282. XLVAL xclose()
  1283. X{
  1284. X    LVAL fptr;
  1285. X
  1286. X    /* get file pointer */
  1287. X    fptr = xlgastream();
  1288. X    xllastarg();
  1289. X
  1290. X    /* make sure the file exists */
  1291. X    if (getfile(fptr) == NULL)
  1292. X    xlfail("file not open");
  1293. X
  1294. X    /* close the file */
  1295. X    osclose(getfile(fptr));
  1296. X    setfile(fptr,NULL);
  1297. X
  1298. X    /* return nil */
  1299. X    return (NIL);
  1300. X}
  1301. X
  1302. X/* xrdchar - read a character from a file */
  1303. XLVAL xrdchar()
  1304. X{
  1305. X    LVAL fptr;
  1306. X    int ch;
  1307. X
  1308. X    /* get file pointer */
  1309. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  1310. X    xllastarg();
  1311. X
  1312. X    /* get character and check for eof */
  1313. X    return ((ch = xlgetc(fptr)) == EOF ? NIL : cvchar(ch));
  1314. X}
  1315. X
  1316. X/* xrdbyte - read a byte from a file */
  1317. XLVAL xrdbyte()
  1318. X{
  1319. X    LVAL fptr;
  1320. X    int ch;
  1321. X
  1322. X    /* get file pointer */
  1323. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  1324. X    xllastarg();
  1325. X
  1326. X    /* get character and check for eof */
  1327. X    return ((ch = xlgetc(fptr)) == EOF ? NIL : cvfixnum((FIXTYPE)ch));
  1328. X}
  1329. X
  1330. X/* xpkchar - peek at a character from a file */
  1331. XLVAL xpkchar()
  1332. X{
  1333. X    LVAL flag,fptr;
  1334. X    int ch;
  1335. X
  1336. X    /* peek flag and get file pointer */
  1337. X    flag = (moreargs() ? xlgetarg() : NIL);
  1338. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  1339. X    xllastarg();
  1340. X
  1341. X    /* skip leading white space and get a character */
  1342. X    if (flag)
  1343. X    while ((ch = xlpeek(fptr)) != EOF && isspace(ch))
  1344. X        xlgetc(fptr);
  1345. X    else
  1346. X    ch = xlpeek(fptr);
  1347. X
  1348. X    /* return the character */
  1349. X    return (ch == EOF ? NIL : cvchar(ch));
  1350. X}
  1351. X
  1352. X/* xwrchar - write a character to a file */
  1353. XLVAL xwrchar()
  1354. X{
  1355. X    LVAL fptr,chr;
  1356. X
  1357. X    /* get the character and file pointer */
  1358. X    chr = xlgachar();
  1359. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  1360. X    xllastarg();
  1361. X
  1362. X    /* put character to the file */
  1363. X    xlputc(fptr,getchcode(chr));
  1364. X
  1365. X    /* return the character */
  1366. X    return (chr);
  1367. X}
  1368. X
  1369. X/* xwrbyte - write a byte to a file */
  1370. XLVAL xwrbyte()
  1371. X{
  1372. X    LVAL fptr,chr;
  1373. X
  1374. X    /* get the byte and file pointer */
  1375. X    chr = xlgafixnum();
  1376. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  1377. X    xllastarg();
  1378. X
  1379. X    /* put byte to the file */
  1380. X    xlputc(fptr,(int)getfixnum(chr));
  1381. X
  1382. X    /* return the character */
  1383. X    return (chr);
  1384. X}
  1385. X
  1386. X/* xreadline - read a line from a file */
  1387. XLVAL xreadline()
  1388. X{
  1389. X    unsigned char buf[STRMAX+1],*p,*sptr;
  1390. X    LVAL fptr,str,newstr;
  1391. X    int len,blen,ch;
  1392. X
  1393. X    /* protect some pointers */
  1394. X    xlsave1(str);
  1395. X
  1396. X    /* get file pointer */
  1397. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  1398. X    xllastarg();
  1399. X
  1400. X    /* get character and check for eof */
  1401. X    len = blen = 0; p = buf;
  1402. X    while ((ch = xlgetc(fptr)) != EOF && ch != '\n') {
  1403. X
  1404. X    /* check for buffer overflow */
  1405. X    if (blen >= STRMAX) {
  1406. X         newstr = newstring(len + STRMAX + 1);
  1407. X        sptr = getstring(newstr); *sptr = '\0';
  1408. X        if (str) strcat(sptr,getstring(str));
  1409. X        *p = '\0'; strcat(sptr,buf);
  1410. X        p = buf; blen = 0;
  1411. X        len += STRMAX;
  1412. X        str = newstr;
  1413. X    }
  1414. X
  1415. X    /* store the character */
  1416. X    *p++ = ch; ++blen;
  1417. X    }
  1418. X
  1419. X    /* check for end of file */
  1420. X    if (len == 0 && p == buf && ch == EOF) {
  1421. X    xlpop();
  1422. X    return (NIL);
  1423. X    }
  1424. X
  1425. X    /* append the last substring */
  1426. X    if (str == NIL || blen) {
  1427. X    newstr = newstring(len + blen + 1);
  1428. X    sptr = getstring(newstr); *sptr = '\0';
  1429. X    if (str) strcat(sptr,getstring(str));
  1430. X    *p = '\0'; strcat(sptr,buf);
  1431. X    str = newstr;
  1432. X    }
  1433. X
  1434. X    /* restore the stack */
  1435. X    xlpop();
  1436. X
  1437. X    /* return the string */
  1438. X    return (str);
  1439. X}
  1440. X
  1441. X
  1442. X/* xmkstrinput - make a string input stream */
  1443. XLVAL xmkstrinput()
  1444. X{
  1445. X    int start,end,len,i;
  1446. X    unsigned char *str;
  1447. X    LVAL string,val;
  1448. X
  1449. X    /* protect the return value */
  1450. X    xlsave1(val);
  1451. X    
  1452. X    /* get the string and length */
  1453. X    string = xlgastring();
  1454. X    str = getstring(string);
  1455. X    len = getslength(string) - 1;
  1456. X
  1457. X    /* get the starting offset */
  1458. X    if (moreargs()) {
  1459. X    val = xlgafixnum();
  1460. X    start = (int)getfixnum(val);
  1461. X    }
  1462. X    else start = 0;
  1463. X
  1464. X    /* get the ending offset */
  1465. X    if (moreargs()) {
  1466. X    val = xlgafixnum();
  1467. X    end = (int)getfixnum(val);
  1468. X    }
  1469. X    else end = len;
  1470. X    xllastarg();
  1471. X
  1472. X    /* check the bounds */
  1473. X    if (start < 0 || start > len)
  1474. X    xlerror("string index out of bounds",cvfixnum((FIXTYPE)start));
  1475. X    if (end < 0 || end > len)
  1476. X    xlerror("string index out of bounds",cvfixnum((FIXTYPE)end));
  1477. X
  1478. X    /* make the stream */
  1479. X    val = newustream();
  1480. X
  1481. X    /* copy the substring into the stream */
  1482. X    for (i = start; i < end; ++i)
  1483. X    xlputc(val,str[i]);
  1484. X
  1485. X    /* restore the stack */
  1486. X    xlpop();
  1487. X
  1488. X    /* return the new stream */
  1489. X    return (val);
  1490. X}
  1491. X
  1492. X/* xmkstroutput - make a string output stream */
  1493. XLVAL xmkstroutput()
  1494. X{
  1495. X    return (newustream());
  1496. X}
  1497. X
  1498. X/* xgetstroutput - get output stream string */
  1499. XLVAL xgetstroutput()
  1500. X{
  1501. X    LVAL stream;
  1502. X    stream = xlgaustream();
  1503. X    xllastarg();
  1504. X    return (getstroutput(stream));
  1505. X}
  1506. X
  1507. X/* xgetlstoutput - get output stream list */
  1508. XLVAL xgetlstoutput()
  1509. X{
  1510. X    LVAL stream,val;
  1511. X
  1512. X    /* get the stream */
  1513. X    stream = xlgaustream();
  1514. X    xllastarg();
  1515. X
  1516. X    /* get the output character list */
  1517. X    val = gethead(stream);
  1518. X
  1519. X    /* empty the character list */
  1520. X    sethead(stream,NIL);
  1521. X    settail(stream,NIL);
  1522. X
  1523. X    /* return the list */
  1524. X    return (val);
  1525. X}
  1526. X
  1527. X/* xformat - formatted output function */
  1528. XLVAL xformat()
  1529. X{
  1530. X    LVAL fmtstring,stream,val;
  1531. X    unsigned char *fmt;
  1532. X    int ch;
  1533. X
  1534. X    /* protect some pointers */
  1535. X    xlstkcheck(2);
  1536. X    xlsave(fmtstring);
  1537. X    xlsave(stream);
  1538. X
  1539. X    /* get the stream and format string */
  1540. X    stream = xlgetarg();
  1541. X    if (stream == NIL)
  1542. X    val = stream = newustream();
  1543. X    else {
  1544. X    if (stream == true)
  1545. X        stream = getvalue(s_stdout);
  1546. X    else if (!streamp(stream) && !ustreamp(stream))
  1547. X        xlbadtype(stream);
  1548. X    val = NIL;
  1549. X    }
  1550. X    fmtstring = xlgastring();
  1551. X    fmt = getstring(fmtstring);
  1552. X
  1553. X    /* process the format string */
  1554. X    while (ch = *fmt++)
  1555. X    if (ch == '~') {
  1556. X        switch (*fmt++) {
  1557. X        case '\0':
  1558. X        xlerror("expecting a format directive",cvstring(fmt-1));
  1559. X        case 'a': case 'A':
  1560. X        xlprint(stream,xlgetarg(),FALSE);
  1561. X        break;
  1562. X        case 's': case 'S':
  1563. X        xlprint(stream,xlgetarg(),TRUE);
  1564. X        break;
  1565. X        case '%':
  1566. X        xlterpri(stream);
  1567. X        break;
  1568. X        case '~':
  1569. X        xlputc(stream,'~');
  1570. X        break;
  1571. X        case '\n':
  1572. X        while (*fmt && *fmt != '\n' && isspace(*fmt))
  1573. X            ++fmt;
  1574. X        break;
  1575. X        default:
  1576. X        xlerror("unknown format directive",cvstring(fmt-1));
  1577. X        }
  1578. X    }
  1579. X    else
  1580. X        xlputc(stream,ch);
  1581. X    
  1582. X    /* get the output string for a stream argument of NIL */
  1583. X    if (val) val = getstroutput(val);
  1584. X    xlpopn(2);
  1585. X        
  1586. X    /* return the value */
  1587. X    return (val);
  1588. X}
  1589. X
  1590. X/* getstroutput - get the output stream string (internal) */
  1591. XLOCAL LVAL getstroutput(stream)
  1592. X  LVAL stream;
  1593. X{
  1594. X    unsigned char *str;
  1595. X    LVAL next,val;
  1596. X    int len,ch;
  1597. X
  1598. X    /* compute the length of the stream */
  1599. X    for (len = 0, next = gethead(stream); next != NIL; next = cdr(next))
  1600. X    ++len;
  1601. X
  1602. X    /* create a new string */
  1603. X    val = newstring(len + 1);
  1604. X    
  1605. X    /* copy the characters into the new string */
  1606. X    str = getstring(val);
  1607. X    while ((ch = xlgetc(stream)) != EOF)
  1608. X    *str++ = ch;
  1609. X    *str = '\0';
  1610. X
  1611. X    /* return the string */
  1612. X    return (val);
  1613. X}
  1614. X
  1615. END_OF_FILE
  1616. if test 11944 -ne `wc -c <'src/xlisp/xcore/c/xlfio.c'`; then
  1617.     echo shar: \"'src/xlisp/xcore/c/xlfio.c'\" unpacked with wrong size!
  1618. fi
  1619. # end of 'src/xlisp/xcore/c/xlfio.c'
  1620. fi
  1621. if test -f 'src/xlisp/xcore/c/xlisp.h' -a "${1}" != "-c" ; then 
  1622.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlisp.h'\"
  1623. else
  1624. echo shar: Extracting \"'src/xlisp/xcore/c/xlisp.h'\" \(13662 characters\)
  1625. sed "s/^X//" >'src/xlisp/xcore/c/xlisp.h' <<'END_OF_FILE'
  1626. X/*
  1627. X* -*-C-*-
  1628. X********************************************************************************
  1629. X*
  1630. X* File:         xlisp.h
  1631. X* RCS:          $Header: xlisp.h,v 1.6 89/12/17 19:05:05 mayer Exp $
  1632. X* Description:  libXlisp.a external interfaces
  1633. X* Author:       David Michael Betz; Niels Mayer
  1634. X* Created:      
  1635. X* Modified:     Sun Dec 17 04:50:59 1989 (Niels Mayer) mayer@hplnpm
  1636. X* Language:     C
  1637. X* Package:      N/A
  1638. X* Status:       X11r4 contrib tape release
  1639. X*
  1640. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  1641. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  1642. X*
  1643. X* Permission to use, copy, modify, distribute, and sell this software and its
  1644. X* documentation for any purpose is hereby granted without fee, provided that
  1645. X* the above copyright notice appear in all copies and that both that
  1646. X* copyright notice and this permission notice appear in supporting
  1647. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  1648. X* used in advertising or publicity pertaining to distribution of the software
  1649. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  1650. X* make no representations about the suitability of this software for any
  1651. X* purpose. It is provided "as is" without express or implied warranty.
  1652. X*
  1653. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  1654. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  1655. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  1656. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  1657. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  1658. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1659. X* PERFORMANCE OF THIS SOFTWARE.
  1660. X*
  1661. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  1662. X* 
  1663. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  1664. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  1665. X*
  1666. X********************************************************************************
  1667. X*/
  1668. X
  1669. X#ifndef __XLISP_H__
  1670. X#define __XLISP_H__
  1671. X
  1672. X#include <stdio.h>
  1673. X#include <ctype.h>
  1674. X#include <setjmp.h>
  1675. X
  1676. X/* NNODES    number of nodes to allocate in each request (1000) */
  1677. X/* EDEPTH    evaluation stack depth (2000) */
  1678. X/* ADEPTH    argument stack depth (1000) */
  1679. X/* FORWARD    type of a forward declaration () */
  1680. X/* LOCAL    type of a local function (static) */
  1681. X/* AFMT        printf format for addresses ("%x") */
  1682. X/* FIXTYPE    data type for fixed point numbers (long) */
  1683. X/* ITYPE    fixed point input conversion routine type (long atol()) */
  1684. X/* ICNV        fixed point input conversion routine (atol) */
  1685. X/* IFMT        printf format for fixed point numbers ("%ld") */
  1686. X/* FLOTYPE    data type for floating point numbers (float) */
  1687. X/* OFFTYPE    number the size of an address (int) */
  1688. X
  1689. X
  1690. X/* for BSD & SYSV Unix. */
  1691. X#ifdef UNIX
  1692. X#define NNODES        2000
  1693. X#define AFMT        "%lx"    /* added by NPM */
  1694. X#define OFFTYPE        long    /* added by NPM */
  1695. X#define SAVERESTORE
  1696. X#endif
  1697. X
  1698. X/* for Mips C compiler - Silicon Graphhics */
  1699. X#ifdef _BSD_COMPAT
  1700. X#define LOCAL
  1701. X#endif
  1702. X
  1703. X/* for the Turbo C compiler - MS-DOS, large model */
  1704. X#ifdef _TURBOC_
  1705. X#define NNODES        2000
  1706. X#define AFMT        "%lx"
  1707. X#define OFFTYPE        long
  1708. X#define SAVERESTORE
  1709. X#endif
  1710. X
  1711. X/* for the AZTEC C compiler - MS-DOS, large model */
  1712. X#ifdef AZTEC_LM
  1713. X#define NNODES        2000
  1714. X#define AFMT        "%lx"
  1715. X#define OFFTYPE        long
  1716. X#define CVPTR(x)    ptrtoabs(x)
  1717. X#define NIL        (void *)0
  1718. Xextern long ptrtoabs();
  1719. X#define SAVERESTORE
  1720. X#endif
  1721. X
  1722. X/* for the AZTEC C compiler - Macintosh */
  1723. X#ifdef AZTEC_MAC
  1724. X#define NNODES        2000
  1725. X#define AFMT        "%lx"
  1726. X#define OFFTYPE        long
  1727. X#define NIL        (void *)0
  1728. X#define SAVERESTORE
  1729. X#endif
  1730. X
  1731. X/* for the AZTEC C compiler - Amiga */
  1732. X#ifdef AZTEC_AMIGA
  1733. X#define NNODES        2000
  1734. X#define AFMT        "%lx"
  1735. X#define OFFTYPE        long
  1736. X#define NIL        (void *)0
  1737. X#define SAVERESTORE
  1738. X#endif
  1739. X
  1740. X/* for the Lightspeed C compiler - Macintosh */
  1741. X#ifdef LSC
  1742. X#define NNODES        2000
  1743. X#define AFMT        "%lx"
  1744. X#define OFFTYPE        long
  1745. X#define NIL        (void *)0
  1746. X#define SAVERESTORE
  1747. X#endif
  1748. X
  1749. X/* for the Microsoft C compiler - MS-DOS, large model */
  1750. X#ifdef MSC
  1751. X#define NNODES        2000
  1752. X#define AFMT        "%lx"
  1753. X#define OFFTYPE        long
  1754. X#endif
  1755. X
  1756. X/* for the Mark Williams C compiler - Atari ST */
  1757. X#ifdef MWC
  1758. X#define AFMT        "%lx"
  1759. X#define OFFTYPE        long
  1760. X#endif
  1761. X
  1762. X/* for the Lattice C compiler - Atari ST */
  1763. X#ifdef LATTICE
  1764. X#define FIXTYPE        int
  1765. X#define ITYPE        int atoi()
  1766. X#define ICNV(n)        atoi(n)
  1767. X#define IFMT        "%d"
  1768. X#endif
  1769. X
  1770. X/* for the Digital Research C compiler - Atari ST */
  1771. X#ifdef DR
  1772. X#define LOCAL
  1773. X#define AFMT        "%lx"
  1774. X#define OFFTYPE        long
  1775. X#undef NULL
  1776. X#define NULL        0L
  1777. X#endif
  1778. X
  1779. X
  1780. X/* default important definitions */
  1781. X#ifndef NNODES
  1782. X#define NNODES        1000
  1783. X#endif
  1784. X#ifndef EDEPTH
  1785. X#define EDEPTH        2000
  1786. X#endif
  1787. X#ifndef ADEPTH
  1788. X#define ADEPTH        1000
  1789. X#endif
  1790. X#ifndef FORWARD
  1791. X#define FORWARD
  1792. X#endif
  1793. X#ifndef LOCAL
  1794. X#define LOCAL        static
  1795. X#endif
  1796. X#ifndef AFMT
  1797. X#define AFMT        "%x"
  1798. X#endif
  1799. X#ifndef FIXTYPE
  1800. X#define FIXTYPE        long
  1801. X#endif
  1802. X#ifndef ITYPE
  1803. X#define ITYPE        long atol()
  1804. X#endif
  1805. X#ifndef ICNV
  1806. X#define ICNV(n)        atol(n)
  1807. X#endif
  1808. X#ifndef IFMT
  1809. X#define IFMT        "%ld"
  1810. X#endif
  1811. X#ifndef FLOTYPE
  1812. X#define FLOTYPE        double
  1813. X#endif
  1814. X#ifndef OFFTYPE
  1815. X#define OFFTYPE        int
  1816. X#endif
  1817. X#ifndef CVPTR
  1818. X#define CVPTR(x)    (x)
  1819. X#endif
  1820. X#ifndef UCHAR
  1821. X#define UCHAR        unsigned char
  1822. X#endif
  1823. X
  1824. X/* useful definitions */
  1825. X#ifndef TRUE
  1826. X#define TRUE    (1)
  1827. X#endif
  1828. X#ifndef FALSE
  1829. X#define FALSE    (0)
  1830. X#endif
  1831. X#ifndef NIL
  1832. X#define NIL    (LVAL )0
  1833. X#endif
  1834. X
  1835. X/* instance variable numbers for the class 'Class' */
  1836. X#define MESSAGES    0    /* list   of messages */
  1837. X#define IVARS        1    /* list   of instance variable names */
  1838. X#define CVARS        2    /* list   of class variable names */
  1839. X#define CVALS        3    /* vector of class variable values */
  1840. X#define SUPERCLASS    4    /* pointer to the superclass */
  1841. X#define IVARCNT        5    /* number of class instance variables */
  1842. X#define IVARTOTAL    6    /* total number of instance variables */
  1843. X/* number of instance variables for the class 'Class' */
  1844. X#define CLASSSIZE    7
  1845. X
  1846. X/* Include PROVIDE_XXX #defines for extension modules. *//* JSP */
  1847. X#define MODULE_XLISP_H_PROVIDES
  1848. X#include "../../xmodules.h"
  1849. X#undef MODULE_XLISP_H_PROVIDES
  1850. X
  1851. X/* include the dynamic memory definitions */
  1852. X#include "xldmem.h"
  1853. X
  1854. X/* program limits */
  1855. X#define STRMAX        100        /* maximum length of a string constant */
  1856. X#define HSIZE        199        /* symbol hash table size */
  1857. X#define SAMPLE        100        /* control character sample rate */
  1858. X
  1859. X/* function table offsets for the initialization functions */
  1860. X#define FT_RMHASH    0
  1861. X#define FT_RMQUOTE    1
  1862. X#define FT_RMDQUOTE    2
  1863. X#define FT_RMBQUOTE    3
  1864. X#define FT_RMCOMMA    4
  1865. X#define FT_RMLPAR    5
  1866. X#define FT_RMRPAR    6
  1867. X#define FT_RMSEMI    7
  1868. X/* #define xxxxxx       8 */
  1869. X/* #define yyyyyy       9 */
  1870. X
  1871. X#define FT_CLNEW    10
  1872. X#define FT_CLISNEW    11
  1873. X#define FT_CLANSWER    12
  1874. X#define FT_OBISNEW    13
  1875. X#define FT_OBCLASS    14
  1876. X#define FT_OBSHOW    15
  1877. X
  1878. X#define LAST_FUNTAB_POINTER_USED_BY_libXlisp FT_OBSHOW
  1879. X
  1880. X/* include hybrid function in xlisp symbol table */ /* Voodoo */
  1881. X/* use from within user implemented xlinclude_hybrid_prims */    
  1882. X/* or from within user implemented .h which xmodules.h includes */
  1883. X#define DEFINE_SUBR(a,b)   xldefine_prim(a, SUBR, b);
  1884. X#define DEFINE_FSUBR(a,b)  xldefine_prim(a, FSUBR, b);
  1885. X
  1886. X/* macro to push a value onto the argument stack */
  1887. X#define pusharg(x)    {if (xlsp >= xlargstktop) xlargstkoverflow();\
  1888. X             *xlsp++ = (x);}
  1889. X
  1890. X/* macros to protect pointers */
  1891. X#define xlstkcheck(n)    {if (xlstack - (n) < xlstkbase) xlstkoverflow();}
  1892. X#define xlsave(n)    {*--xlstack = &n; n = NIL;}
  1893. X#define xlprotect(n)    {*--xlstack = &n;}
  1894. X
  1895. X/* check the stack and protect a single pointer */
  1896. X#define xlsave1(n)    {if (xlstack <= xlstkbase) xlstkoverflow();\
  1897. X                         *--xlstack = &n; n = NIL;}
  1898. X#define xlprot1(n)    {if (xlstack <= xlstkbase) xlstkoverflow();\
  1899. X                         *--xlstack = &n;}
  1900. X
  1901. X/* macros to pop pointers off the stack */
  1902. X#define xlpop()        {++xlstack;}
  1903. X#define xlpopn(n)    {xlstack+=(n);}
  1904. X
  1905. X/* macros to manipulate the lexical environment */
  1906. X#define xlframe(e)    cons(NIL,e)
  1907. X#define xlbind(s,v)    xlpbind(s,v,xlenv)
  1908. X#define xlfbind(s,v)    xlpbind(s,v,xlfenv);
  1909. X#define xlpbind(s,v,e)    {rplaca(e,cons(cons(s,v),car(e)));}
  1910. X
  1911. X/* macros to manipulate the dynamic environment */
  1912. X#define xldbind(s,v)    {xldenv = cons(cons(s,getvalue(s)),xldenv);\
  1913. X             setvalue(s,v);}
  1914. X#define xlunbind(e)    {for (; xldenv != (e); xldenv = cdr(xldenv))\
  1915. X               setvalue(car(car(xldenv)),cdr(car(xldenv)));}
  1916. X
  1917. X/* type predicates */                   
  1918. X#define atom(x)        ((x) == NIL || ntype(x) != CONS)
  1919. X#define null(x)        ((x) == NIL)
  1920. X#define listp(x)    ((x) == NIL || ntype(x) == CONS)
  1921. X#define consp(x)    ((x) && ntype(x) == CONS)
  1922. X#define subrp(x)    ((x) && ntype(x) == SUBR)
  1923. X#define fsubrp(x)    ((x) && ntype(x) == FSUBR)
  1924. X#define stringp(x)    ((x) && ntype(x) == STRING)
  1925. X#define symbolp(x)    ((x) && ntype(x) == SYMBOL)
  1926. X#define streamp(x)    ((x) && ntype(x) == STREAM)
  1927. X
  1928. X#define objectp(x)    ((x) && ntype(x) == OBJECT)
  1929. X
  1930. X#define fixp(x)        ((x) && ntype(x) == FIXNUM)
  1931. X#define floatp(x)    ((x) && ntype(x) == FLONUM)
  1932. X#define vectorp(x)    ((x) && ntype(x) == VECTOR)
  1933. X#define closurep(x)    ((x) && ntype(x) == CLOSURE)
  1934. X#define charp(x)    ((x) && ntype(x) == CHAR)
  1935. X#define ustreamp(x)    ((x) && ntype(x) == USTREAM)
  1936. X#define structp(x)    ((x) && ntype(x) == STRUCT)
  1937. X#define boundp(x)    (getvalue(x) != s_unbound)
  1938. X#define fboundp(x)    (getfunction(x) != s_unbound)
  1939. X
  1940. X/* shorthand functions */
  1941. X#define consa(x)    cons(x,NIL)
  1942. X#define consd(x)    cons(NIL,x)
  1943. X
  1944. X/* set element of a vector */ /* Voodoo */
  1945. X#define stuff_fixnum(arg, ind, val) ((arg)->n_vdata[ind])->n_fixnum = (val)
  1946. X#define stuff_flonum(arg, ind, val) ((arg)->n_vdata[ind])->n_flonum = (val)
  1947. X
  1948. X/* argument list parsing macros */
  1949. X#define xlgetarg()    (testarg(nextarg()))
  1950. X#define xllastarg()    {if (xlargc != 0) xltoomany();}
  1951. X#define testarg(e)    (moreargs() ? (e) : xltoofew())
  1952. X#define typearg(tp)    (tp(*xlargv) ? nextarg() : xlbadtype(*xlargv))
  1953. X#define nextarg()    (--xlargc, *xlargv++)
  1954. X#define moreargs()    (xlargc > 0)
  1955. X
  1956. X/* macros to get arguments of a particular type */
  1957. X#define xlgacons()    (testarg(typearg(consp)))
  1958. X#define xlgalist()    (testarg(typearg(listp)))
  1959. X#define xlgasymbol()    (testarg(typearg(symbolp)))
  1960. X#define xlgastring()    (testarg(typearg(stringp)))
  1961. X#define xlgaobject()    (testarg(typearg(objectp)))
  1962. X#define xlgafixnum()    (testarg(typearg(fixp)))
  1963. X#define xlgaflonum()    (testarg(typearg(floatp)))
  1964. X#define xlgachar()    (testarg(typearg(charp)))
  1965. X#define xlgavector()    (testarg(typearg(vectorp)))
  1966. X#define xlgastream()    (testarg(typearg(streamp)))
  1967. X#define xlgaustream()    (testarg(typearg(ustreamp)))
  1968. X#define xlgaclosure()    (testarg(typearg(closurep)))
  1969. X#define xlgastruct()    (testarg(typearg(structp)))
  1970. X
  1971. X#ifndef OPTIMAL        /* Voodoo */
  1972. X#define xlsetjmp(context)         setjmp(context)
  1973. X#define xllongjmp(context, mask)     longjmp(context, mask)
  1974. X#else
  1975. X#define xlsetjmp(context)         0
  1976. X#define xllongjmp(context, mask) \
  1977. X{ \
  1978. X    xlfatal("can't recover, bye..."); \
  1979. X    exit(0); \
  1980. X    }
  1981. X#endif
  1982. X
  1983. X/* function definition structure */
  1984. Xtypedef struct {
  1985. X    char *fd_name;    /* function name */
  1986. X    int fd_type;    /* function type */
  1987. X    LVAL (*fd_subr)();    /* function entry point */
  1988. X} FUNDEF;
  1989. X
  1990. X/* execution context flags */
  1991. X#define CF_GO        0x0001
  1992. X#define CF_RETURN    0x0002
  1993. X#define CF_THROW    0x0004
  1994. X#define CF_ERROR    0x0008
  1995. X#define CF_CLEANUP    0x0010
  1996. X#define CF_CONTINUE    0x0020
  1997. X#define CF_TOPLEVEL    0x0040
  1998. X#define CF_BRKLEVEL    0x0080
  1999. X#define CF_UNWIND    0x0100
  2000. X
  2001. X/* execution context */
  2002. Xtypedef struct context {
  2003. X    int c_flags;            /* context type flags */
  2004. X    LVAL c_expr;            /* expression (type dependant) */
  2005. X    jmp_buf c_jmpbuf;            /* longjmp context */
  2006. X    struct context *c_xlcontext;    /* old value of xlcontext */
  2007. X    LVAL **c_xlstack;            /* old value of xlstack */
  2008. X    LVAL *c_xlargv;            /* old value of xlargv */
  2009. X    int c_xlargc;            /* old value of xlargc */
  2010. X    LVAL *c_xlfp;            /* old value of xlfp */
  2011. X    LVAL *c_xlsp;            /* old value of xlsp */
  2012. X    LVAL c_xlenv;            /* old value of xlenv */
  2013. X    LVAL c_xlfenv;            /* old value of xlfenv */
  2014. X    LVAL c_xldenv;            /* old value of xldenv */
  2015. X} CONTEXT;
  2016. X
  2017. X/* external variables */
  2018. Xextern LVAL **xlstktop;           /* top of the evaluation stack */
  2019. Xextern LVAL **xlstkbase;    /* base of the evaluation stack */
  2020. Xextern LVAL **xlstack;        /* evaluation stack pointer */
  2021. Xextern LVAL *xlargstkbase;    /* base of the argument stack */
  2022. Xextern LVAL *xlargstktop;    /* top of the argument stack */
  2023. Xextern LVAL *xlfp;        /* argument frame pointer */
  2024. Xextern LVAL *xlsp;        /* argument stack pointer */
  2025. Xextern LVAL *xlargv;        /* current argument vector */
  2026. Xextern int xlargc;        /* current argument count */
  2027. X
  2028. X/* external procedure declarations */
  2029. Xextern LVAL xleval();        /* evaluate an expression */
  2030. Xextern LVAL xlapply();        /* apply a function to arguments */
  2031. Xextern LVAL xlsubr();        /* enter a subr/fsubr */
  2032. Xextern LVAL xlenter();        /* enter a symbol */
  2033. Xextern LVAL xlmakesym();    /* make an uninterned symbol */
  2034. Xextern LVAL xlgetvalue();    /* get value of a symbol (checked) */
  2035. Xextern LVAL xlxgetvalue();    /* get value of a symbol */
  2036. Xextern LVAL xlgetfunction();    /* get functional value of a symbol */
  2037. Xextern LVAL xlxgetfunction();    /* get functional value of a symbol (checked) */
  2038. Xextern LVAL xlexpandmacros();    /* expand macros in a form */
  2039. Xextern LVAL xlgetprop();    /* get the value of a property */
  2040. Xextern LVAL xlclose();        /* create a function closure */
  2041. X
  2042. Xextern void xldefine_prim();    /* load xlisp function */ /* Voodoo */
  2043. X
  2044. X/* argument list parsing functions */
  2045. Xextern LVAL xlgetfile();          /* get a file/stream argument */
  2046. Xextern LVAL xlgetfname();    /* get a filename argument */
  2047. X
  2048. X/* error reporting functions (don't *really* return at all) */
  2049. Xextern LVAL xltoofew();        /* report "too few arguments" error */
  2050. Xextern LVAL xlbadtype();    /* report "bad argument type" error */
  2051. X
  2052. X
  2053. X/* Include hybrid-class functions. *//* JSP */
  2054. X/* (Last so you can #undef stuff.) *//* JSP */
  2055. X#define MODULE_XLISP_H_GLOBALS
  2056. X#include "../../xmodules.h"
  2057. X#undef MODULE_XLISP_H_GLOBALS
  2058. X
  2059. X#endif /* __XLISP_H__ */
  2060. END_OF_FILE
  2061. if test 13662 -ne `wc -c <'src/xlisp/xcore/c/xlisp.h'`; then
  2062.     echo shar: \"'src/xlisp/xcore/c/xlisp.h'\" unpacked with wrong size!
  2063. fi
  2064. # end of 'src/xlisp/xcore/c/xlisp.h'
  2065. fi
  2066. if test -f 'src/xlisp/xcore/c/xlmath.c' -a "${1}" != "-c" ; then 
  2067.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlmath.c'\"
  2068. else
  2069. echo shar: Extracting \"'src/xlisp/xcore/c/xlmath.c'\" \(11975 characters\)
  2070. sed "s/^X//" >'src/xlisp/xcore/c/xlmath.c' <<'END_OF_FILE'
  2071. X/* -*-C-*-
  2072. X********************************************************************************
  2073. X*
  2074. X* File:         xlmath.c
  2075. X* RCS:          $Header: xlmath.c,v 1.3 89/11/25 05:40:35 mayer Exp $
  2076. X* Description:  xlisp built-in arithmetic functions
  2077. X* Author:       David Michael Betz
  2078. X* Created:      
  2079. X* Modified:     Sat Nov 25 05:40:27 1989 (Niels Mayer) mayer@hplnpm
  2080. X* Language:     C
  2081. X* Package:      N/A
  2082. X* Status:       X11r4 contrib tape release
  2083. X*
  2084. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  2085. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  2086. X*
  2087. X* Permission to use, copy, modify, distribute, and sell this software and its
  2088. X* documentation for any purpose is hereby granted without fee, provided that
  2089. X* the above copyright notice appear in all copies and that both that
  2090. X* copyright notice and this permission notice appear in supporting
  2091. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  2092. X* used in advertising or publicity pertaining to distribution of the software
  2093. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  2094. X* make no representations about the suitability of this software for any
  2095. X* purpose. It is provided "as is" without express or implied warranty.
  2096. X*
  2097. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  2098. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  2099. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  2100. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2101. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2102. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2103. X* PERFORMANCE OF THIS SOFTWARE.
  2104. X*
  2105. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  2106. X* 
  2107. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  2108. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  2109. X*
  2110. X********************************************************************************
  2111. X*/
  2112. Xstatic char rcs_identity[] = "@(#)$Header: xlmath.c,v 1.3 89/11/25 05:40:35 mayer Exp $";
  2113. X
  2114. X
  2115. X#include "xlisp.h"
  2116. X#include <math.h>
  2117. X
  2118. X/* external variables */
  2119. Xextern LVAL true;
  2120. X
  2121. X/* forward declarations */
  2122. XFORWARD LVAL unary();
  2123. XFORWARD LVAL binary();
  2124. XFORWARD LVAL predicate();
  2125. XFORWARD LVAL compare();
  2126. X
  2127. X/* binary functions */
  2128. XLVAL xadd()    { return (binary('+')); } /* + */
  2129. XLVAL xsub()    { return (binary('-')); } /* - */
  2130. XLVAL xmul()    { return (binary('*')); } /* * */
  2131. XLVAL xdiv()    { return (binary('/')); } /* / */
  2132. XLVAL xrem()    { return (binary('%')); } /* rem */
  2133. XLVAL xmin()    { return (binary('m')); } /* min */
  2134. XLVAL xmax()    { return (binary('M')); } /* max */
  2135. XLVAL xexpt()   { return (binary('E')); } /* expt */
  2136. XLVAL xlogand() { return (binary('&')); } /* logand */
  2137. XLVAL xlogior() { return (binary('|')); } /* logior */
  2138. XLVAL xlogxor() { return (binary('^')); } /* logxor */
  2139. X
  2140. X/* xgcd - greatest common divisor */
  2141. XLVAL xgcd()
  2142. X{
  2143. X    FIXTYPE m,n,r;
  2144. X    LVAL arg;
  2145. X
  2146. X    if (!moreargs())            /* check for identity case */
  2147. X    return (cvfixnum((FIXTYPE)0));
  2148. X    arg = xlgafixnum();
  2149. X    n = getfixnum(arg);
  2150. X    if (n < (FIXTYPE)0) n = -n;        /* absolute value */
  2151. X    while (moreargs()) {
  2152. X    arg = xlgafixnum();
  2153. X    m = getfixnum(arg);
  2154. X    if (m < (FIXTYPE)0) m = -m;    /* absolute value */
  2155. X    for (;;) {            /* euclid's algorithm */
  2156. X        r = m % n;
  2157. X        if (r == (FIXTYPE)0)
  2158. X        break;
  2159. X        m = n;
  2160. X        n = r;
  2161. X    }
  2162. X    }
  2163. X    return (cvfixnum(n));
  2164. X}
  2165. X
  2166. X/* binary - handle binary operations */
  2167. XLOCAL LVAL binary(fcn)
  2168. X  int fcn;
  2169. X{
  2170. X    FIXTYPE ival,iarg;
  2171. X    FLOTYPE fval,farg;
  2172. X    LVAL arg;
  2173. X    int mode;
  2174. X
  2175. X    /* get the first argument */
  2176. X    arg = xlgetarg();
  2177. X
  2178. X    /* set the type of the first argument */
  2179. X    if (fixp(arg)) {
  2180. X    ival = getfixnum(arg);
  2181. X    mode = 'I';
  2182. X    }
  2183. X    else if (floatp(arg)) {
  2184. X    fval = getflonum(arg);
  2185. X    mode = 'F';
  2186. X    }
  2187. X    else
  2188. X    xlerror("bad argument type",arg);
  2189. X
  2190. X    /* treat a single argument as a special case */
  2191. X    if (!moreargs()) {
  2192. X    switch (fcn) {
  2193. X    case '-':
  2194. X        switch (mode) {
  2195. X        case 'I':
  2196. X        ival = -ival;
  2197. X        break;
  2198. X        case 'F':
  2199. X        fval = -fval;
  2200. X        break;
  2201. X        }
  2202. X        break;
  2203. X    case '/':
  2204. X        switch (mode) {
  2205. X        case 'I':
  2206. X        checkizero(ival);
  2207. X        ival = 1 / ival;
  2208. X        break;
  2209. X        case 'F':
  2210. X        checkfzero(fval);
  2211. X        fval = 1.0 / fval;
  2212. X        break;
  2213. X        }
  2214. X    }
  2215. X    }
  2216. X
  2217. X    /* handle each remaining argument */
  2218. X    while (moreargs()) {
  2219. X
  2220. X    /* get the next argument */
  2221. X    arg = xlgetarg();
  2222. X
  2223. X    /* check its type */
  2224. X    if (fixp(arg)) {
  2225. X        switch (mode) {
  2226. X        case 'I':
  2227. X            iarg = getfixnum(arg);
  2228. X            break;
  2229. X        case 'F':
  2230. X            farg = (FLOTYPE)getfixnum(arg);
  2231. X        break;
  2232. X        }
  2233. X    }
  2234. X    else if (floatp(arg)) {
  2235. X        switch (mode) {
  2236. X        case 'I':
  2237. X            fval = (FLOTYPE)ival;
  2238. X        farg = getflonum(arg);
  2239. X        mode = 'F';
  2240. X        break;
  2241. X        case 'F':
  2242. X            farg = getflonum(arg);
  2243. X        break;
  2244. X        }
  2245. X    }
  2246. X    else
  2247. X        xlerror("bad argument type",arg);
  2248. X
  2249. X    /* accumulate the result value */
  2250. X    switch (mode) {
  2251. X    case 'I':
  2252. X        switch (fcn) {
  2253. X        case '+':    ival += iarg; break;
  2254. X        case '-':    ival -= iarg; break;
  2255. X        case '*':    ival *= iarg; break;
  2256. X        case '/':    checkizero(iarg); ival /= iarg; break;
  2257. X        case '%':    checkizero(iarg); ival %= iarg; break;
  2258. X        case 'M':    if (iarg > ival) ival = iarg; break;
  2259. X        case 'm':    if (iarg < ival) ival = iarg; break;
  2260. X        case '&':    ival &= iarg; break;
  2261. X        case '|':    ival |= iarg; break;
  2262. X        case '^':    ival ^= iarg; break;
  2263. X        default:    badiop();
  2264. X        }
  2265. X        break;
  2266. X    case 'F':
  2267. X        switch (fcn) {
  2268. X        case '+':    fval += farg; break;
  2269. X        case '-':    fval -= farg; break;
  2270. X        case '*':    fval *= farg; break;
  2271. X        case '/':    checkfzero(farg); fval /= farg; break;
  2272. X        case 'M':    if (farg > fval) fval = farg; break;
  2273. X        case 'm':    if (farg < fval) fval = farg; break;
  2274. X        case 'E':    fval = pow(fval,farg); break;
  2275. X        default:    badfop();
  2276. X        }
  2277. X            break;
  2278. X    }
  2279. X    }
  2280. X
  2281. X    /* return the result */
  2282. X    switch (mode) {
  2283. X    case 'I':    return (cvfixnum(ival));
  2284. X    case 'F':    return (cvflonum(fval));
  2285. X    }
  2286. X}
  2287. X
  2288. X/* checkizero - check for integer division by zero */
  2289. XLOCAL checkizero(iarg)
  2290. X  FIXTYPE iarg;
  2291. X{
  2292. X    if (iarg == 0)
  2293. X    xlfail("division by zero");
  2294. X}
  2295. X
  2296. X/* checkfzero - check for floating point division by zero */
  2297. XLOCAL checkfzero(farg)
  2298. X  FLOTYPE farg;
  2299. X{
  2300. X    if (farg == 0.0)
  2301. X    xlfail("division by zero");
  2302. X}
  2303. X
  2304. X/* checkfneg - check for square root of a negative number */
  2305. XLOCAL checkfneg(farg)
  2306. X  FLOTYPE farg;
  2307. X{
  2308. X    if (farg < 0.0)
  2309. X    xlfail("square root of a negative number");
  2310. X}
  2311. X
  2312. X/* unary functions */
  2313. XLVAL xlognot() { return (unary('~')); } /* lognot */
  2314. XLVAL xabs()    { return (unary('A')); } /* abs */
  2315. XLVAL xadd1()   { return (unary('+')); } /* 1+ */
  2316. XLVAL xsub1()   { return (unary('-')); } /* 1- */
  2317. XLVAL xsin()    { return (unary('S')); } /* sin */
  2318. XLVAL xcos()    { return (unary('C')); } /* cos */
  2319. XLVAL xtan()    { return (unary('T')); } /* tan */
  2320. XLVAL xasin()   { return (unary('s')); } /* asin */
  2321. XLVAL xacos()   { return (unary('c')); } /* acos */
  2322. XLVAL xatan()   { return (unary('t')); } /* atan */
  2323. XLVAL xexp()    { return (unary('E')); } /* exp */
  2324. XLVAL xsqrt()   { return (unary('R')); } /* sqrt */
  2325. XLVAL xfix()    { return (unary('I')); } /* truncate */
  2326. XLVAL xfloat()  { return (unary('F')); } /* float */
  2327. XLVAL xrand()   { return (unary('?')); } /* random */
  2328. X
  2329. X/* unary - handle unary operations */
  2330. XLOCAL LVAL unary(fcn)
  2331. X  int fcn;
  2332. X{
  2333. X    FLOTYPE fval;
  2334. X    FIXTYPE ival;
  2335. X    LVAL arg;
  2336. X
  2337. X    /* get the argument */
  2338. X    arg = xlgetarg();
  2339. X    xllastarg();
  2340. X
  2341. X    /* check its type */
  2342. X    if (fixp(arg)) {
  2343. X    ival = getfixnum(arg);
  2344. X    switch (fcn) {
  2345. X    case '~':    ival = ~ival; break;
  2346. X    case 'A':    ival = (ival < 0 ? -ival : ival); break;
  2347. X    case '+':    ival++; break;
  2348. X    case '-':    ival--; break;
  2349. X    case 'I':    break;
  2350. X    case 'F':    return (cvflonum((FLOTYPE)ival));
  2351. X    case '?':    ival = (FIXTYPE)osrand((int)ival); break;
  2352. X    default:    badiop();
  2353. X    }
  2354. X    return (cvfixnum(ival));
  2355. X    }
  2356. X    else if (floatp(arg)) {
  2357. X    fval = getflonum(arg);
  2358. X    switch (fcn) {
  2359. X    case 'A':    fval = (fval < 0.0 ? -fval : fval); break;
  2360. X    case '+':    fval += 1.0; break;
  2361. X    case '-':    fval -= 1.0; break;
  2362. X    case 'S':    fval = sin(fval); break;
  2363. X    case 'C':    fval = cos(fval); break;
  2364. X    case 'T':    fval = tan(fval); break;
  2365. X    case 's':    fval = asin(fval); break;
  2366. X    case 'c':    fval = acos(fval); break;
  2367. X    case 't':    fval = atan(fval); break;
  2368. X    case 'E':    fval = exp(fval); break;
  2369. X    case 'R':    checkfneg(fval); fval = sqrt(fval); break;
  2370. X    case 'I':    return (cvfixnum((FIXTYPE)fval));
  2371. X    case 'F':    break;
  2372. X    default:    badfop();
  2373. X    }
  2374. X    return (cvflonum(fval));
  2375. X    }
  2376. X    else
  2377. X    xlerror("bad argument type",arg);
  2378. X}
  2379. X
  2380. X/* unary predicates */
  2381. XLVAL xminusp() { return (predicate('-')); } /* minusp */
  2382. XLVAL xzerop()  { return (predicate('Z')); } /* zerop */
  2383. XLVAL xplusp()  { return (predicate('+')); } /* plusp */
  2384. XLVAL xevenp()  { return (predicate('E')); } /* evenp */
  2385. XLVAL xoddp()   { return (predicate('O')); } /* oddp */
  2386. X
  2387. X/* predicate - handle a predicate function */
  2388. XLOCAL LVAL predicate(fcn)
  2389. X  int fcn;
  2390. X{
  2391. X    FLOTYPE fval;
  2392. X    FIXTYPE ival;
  2393. X    LVAL arg;
  2394. X
  2395. X    /* get the argument */
  2396. X    arg = xlgetarg();
  2397. X    xllastarg();
  2398. X
  2399. X    /* check the argument type */
  2400. X    if (fixp(arg)) {
  2401. X    ival = getfixnum(arg);
  2402. X    switch (fcn) {
  2403. X    case '-':    ival = (ival < 0); break;
  2404. X    case 'Z':    ival = (ival == 0); break;
  2405. X    case '+':    ival = (ival > 0); break;
  2406. X    case 'E':    ival = ((ival & 1) == 0); break;
  2407. X    case 'O':    ival = ((ival & 1) != 0); break;
  2408. X    default:    badiop();
  2409. X    }
  2410. X    }
  2411. X    else if (floatp(arg)) {
  2412. X    fval = getflonum(arg);
  2413. X    switch (fcn) {
  2414. X    case '-':    ival = (fval < 0); break;
  2415. X    case 'Z':    ival = (fval == 0); break;
  2416. X    case '+':    ival = (fval > 0); break;
  2417. X    default:    badfop();
  2418. X    }
  2419. X    }
  2420. X    else
  2421. X    xlerror("bad argument type",arg);
  2422. X
  2423. X    /* return the result value */
  2424. X    return (ival ? true : NIL);
  2425. X}
  2426. X
  2427. X/* comparison functions */
  2428. XLVAL xlss() { return (compare('<')); } /* < */
  2429. XLVAL xleq() { return (compare('L')); } /* <= */
  2430. XLVAL xequ() { return (compare('=')); } /* = */
  2431. XLVAL xneq() { return (compare('#')); } /* /= */
  2432. XLVAL xgeq() { return (compare('G')); } /* >= */
  2433. XLVAL xgtr() { return (compare('>')); } /* > */
  2434. X
  2435. X/* compare - common compare function */
  2436. XLOCAL LVAL compare(fcn)
  2437. X  int fcn;
  2438. X{
  2439. X    FIXTYPE icmp,ival,iarg;
  2440. X    FLOTYPE fcmp,fval,farg;
  2441. X    LVAL arg;
  2442. X    int mode;
  2443. X
  2444. X    /* get the first argument */
  2445. X    arg = xlgetarg();
  2446. X
  2447. X    /* set the type of the first argument */
  2448. X    if (fixp(arg)) {
  2449. X    ival = getfixnum(arg);
  2450. X    mode = 'I';
  2451. X    }
  2452. X    else if (floatp(arg)) {
  2453. X    fval = getflonum(arg);
  2454. X    mode = 'F';
  2455. X    }
  2456. X    else
  2457. X    xlerror("bad argument type",arg);
  2458. X
  2459. X    /* handle each remaining argument */
  2460. X    for (icmp = TRUE; icmp && moreargs(); ival = iarg, fval = farg) {
  2461. X
  2462. X    /* get the next argument */
  2463. X    arg = xlgetarg();
  2464. X
  2465. X    /* check its type */
  2466. X    if (fixp(arg)) {
  2467. X        switch (mode) {
  2468. X        case 'I':
  2469. X            iarg = getfixnum(arg);
  2470. X            break;
  2471. X        case 'F':
  2472. X            farg = (FLOTYPE)getfixnum(arg);
  2473. X        break;
  2474. X        }
  2475. X    }
  2476. X    else if (floatp(arg)) {
  2477. X        switch (mode) {
  2478. X        case 'I':
  2479. X            fval = (FLOTYPE)ival;
  2480. X        farg = getflonum(arg);
  2481. X        mode = 'F';
  2482. X        break;
  2483. X        case 'F':
  2484. X            farg = getflonum(arg);
  2485. X        break;
  2486. X        }
  2487. X    }
  2488. X    else
  2489. X        xlerror("bad argument type",arg);
  2490. X
  2491. X    /* compute result of the compare */
  2492. X    switch (mode) {
  2493. X    case 'I':
  2494. X        icmp = ival - iarg;
  2495. X        switch (fcn) {
  2496. X        case '<':    icmp = (icmp < 0); break;
  2497. X        case 'L':    icmp = (icmp <= 0); break;
  2498. X        case '=':    icmp = (icmp == 0); break;
  2499. X        case '#':    icmp = (icmp != 0); break;
  2500. X        case 'G':    icmp = (icmp >= 0); break;
  2501. X        case '>':    icmp = (icmp > 0); break;
  2502. X        }
  2503. X        break;
  2504. X    case 'F':
  2505. X        fcmp = fval - farg;
  2506. X        switch (fcn) {
  2507. X        case '<':    icmp = (fcmp < 0.0); break;
  2508. X        case 'L':    icmp = (fcmp <= 0.0); break;
  2509. X        case '=':    icmp = (fcmp == 0.0); break;
  2510. X        case '#':    icmp = (fcmp != 0.0); break;
  2511. X        case 'G':    icmp = (fcmp >= 0.0); break;
  2512. X        case '>':    icmp = (fcmp > 0.0); break;
  2513. X        }
  2514. X        break;
  2515. X    }
  2516. X    }
  2517. X
  2518. X    /* return the result */
  2519. X    return (icmp ? true : NIL);
  2520. X}
  2521. X
  2522. X/* badiop - bad integer operation */
  2523. XLOCAL badiop()
  2524. X{
  2525. X    xlfail("bad integer operation");
  2526. X}
  2527. X
  2528. X/* badfop - bad floating point operation */
  2529. XLOCAL badfop()
  2530. X{
  2531. X    xlfail("bad floating point operation");
  2532. X}
  2533. END_OF_FILE
  2534. if test 11975 -ne `wc -c <'src/xlisp/xcore/c/xlmath.c'`; then
  2535.     echo shar: \"'src/xlisp/xcore/c/xlmath.c'\" unpacked with wrong size!
  2536. fi
  2537. # end of 'src/xlisp/xcore/c/xlmath.c'
  2538. fi
  2539. if test -f 'src/xlisp/xcore/c/xlstruct.c' -a "${1}" != "-c" ; then 
  2540.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlstruct.c'\"
  2541. else
  2542. echo shar: Extracting \"'src/xlisp/xcore/c/xlstruct.c'\" \(12885 characters\)
  2543. sed "s/^X//" >'src/xlisp/xcore/c/xlstruct.c' <<'END_OF_FILE'
  2544. X/* -*-C-*-
  2545. X********************************************************************************
  2546. X*
  2547. X* File:         xlstruct.c
  2548. X* RCS:          $Header: xlstruct.c,v 1.2 89/11/25 05:47:24 mayer Exp $
  2549. X* Description:  the defstruct facility
  2550. X* Author:       David Michael Betz
  2551. X* Created:      
  2552. X* Modified:     Sat Nov 25 05:47:17 1989 (Niels Mayer) mayer@hplnpm
  2553. X* Language:     C
  2554. X* Package:      N/A
  2555. X* Status:       X11r4 contrib tape release
  2556. X*
  2557. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  2558. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  2559. X*
  2560. X* Permission to use, copy, modify, distribute, and sell this software and its
  2561. X* documentation for any purpose is hereby granted without fee, provided that
  2562. X* the above copyright notice appear in all copies and that both that
  2563. X* copyright notice and this permission notice appear in supporting
  2564. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  2565. X* used in advertising or publicity pertaining to distribution of the software
  2566. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  2567. X* make no representations about the suitability of this software for any
  2568. X* purpose. It is provided "as is" without express or implied warranty.
  2569. X*
  2570. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  2571. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  2572. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  2573. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2574. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2575. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2576. X* PERFORMANCE OF THIS SOFTWARE.
  2577. X*
  2578. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  2579. X* 
  2580. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  2581. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  2582. X*
  2583. X********************************************************************************
  2584. X*/
  2585. Xstatic char rcs_identity[] = "@(#)$Header: xlstruct.c,v 1.2 89/11/25 05:47:24 mayer Exp $";
  2586. X
  2587. X
  2588. X#include "xlisp.h"
  2589. X
  2590. X/* external variables */
  2591. Xextern LVAL xlenv,xlfenv;
  2592. Xextern LVAL s_lambda,s_quote,lk_key,true;
  2593. Xextern char buf[];
  2594. X
  2595. X/* local variables */
  2596. Xstatic prefix[STRMAX+1];
  2597. X
  2598. X/* xmkstruct - the '%make-struct' function */
  2599. XLVAL xmkstruct()
  2600. X{
  2601. X    LVAL type,val;
  2602. X    int i;
  2603. X
  2604. X    /* get the structure type */
  2605. X    type = xlgasymbol();
  2606. X
  2607. X    /* make the structure */
  2608. X    val = newstruct(type,xlargc);
  2609. X
  2610. X    /* store each argument */
  2611. X    for (i = 1; moreargs(); ++i)
  2612. X    setelement(val,i,nextarg());
  2613. X    xllastarg();
  2614. X
  2615. X    /* return the structure */
  2616. X    return (val);
  2617. X}
  2618. X
  2619. X/* xcpystruct - the '%copy-struct' function */
  2620. XLVAL xcpystruct()
  2621. X{
  2622. X    LVAL str,val;
  2623. X    int size,i;
  2624. X    str = xlgastruct();
  2625. X    xllastarg();
  2626. X    size = getsz(str);
  2627. X    val = newstruct(getelement(str,0),size-1);
  2628. X    for (i = 1; i < size; ++i)
  2629. X    setelement(val,i,getelement(str,i));
  2630. X    return (val);
  2631. X}
  2632. X
  2633. X/* xstrref - the '%struct-ref' function */
  2634. XLVAL xstrref()
  2635. X{
  2636. X    LVAL str,val;
  2637. X    int i;
  2638. X    str = xlgastruct();
  2639. X    val = xlgafixnum(); i = (int)getfixnum(val);
  2640. X    xllastarg();
  2641. X    return (getelement(str,i));
  2642. X}
  2643. X
  2644. X/* xstrset - the '%struct-set' function */
  2645. XLVAL xstrset()
  2646. X{
  2647. X    LVAL str,val;
  2648. X    int i;
  2649. X    str = xlgastruct();
  2650. X    val = xlgafixnum(); i = (int)getfixnum(val);
  2651. X    val = xlgetarg();
  2652. X    xllastarg();
  2653. X    setelement(str,i,val);
  2654. X    return (val);
  2655. X}
  2656. X
  2657. X/* xstrtypep - the '%struct-type-p' function */
  2658. XLVAL xstrtypep()
  2659. X{
  2660. X    LVAL type,val;
  2661. X    type = xlgasymbol();
  2662. X    val = xlgetarg();
  2663. X    xllastarg();
  2664. X    return (structp(val) && getelement(val,0) == type ? true : NIL);
  2665. X}
  2666. X
  2667. X/* xdefstruct - the 'defstruct' special form */
  2668. XLVAL xdefstruct()
  2669. X{
  2670. X    LVAL structname,slotname,defexpr,sym,tmp,args,body;
  2671. X    LVAL options,oargs,slots;
  2672. X    char *pname;
  2673. X    int slotn;
  2674. X    
  2675. X    /* protect some pointers */
  2676. X    xlstkcheck(6);
  2677. X    xlsave(structname);
  2678. X    xlsave(slotname);
  2679. X    xlsave(defexpr);
  2680. X    xlsave(args);
  2681. X    xlsave(body);
  2682. X    xlsave(tmp);
  2683. X    
  2684. X    /* initialize */
  2685. X    args = body = NIL;
  2686. X    slotn = 0;
  2687. X
  2688. X    /* get the structure name */
  2689. X    tmp = xlgetarg();
  2690. X    if (symbolp(tmp)) {
  2691. X    structname = tmp;
  2692. X    strcpy(prefix,getstring(getpname(structname)));
  2693. X    strcat(prefix,"-");
  2694. X    }
  2695. X
  2696. X    /* get the structure name and options */
  2697. X    else if (consp(tmp) && symbolp(car(tmp))) {
  2698. X    structname = car(tmp);
  2699. X    strcpy(prefix,getstring(getpname(structname)));
  2700. X    strcat(prefix,"-");
  2701. X
  2702. X    /* handle the list of options */
  2703. X    for (options = cdr(tmp); consp(options); options = cdr(options)) {
  2704. X
  2705. X        /* get the next argument */
  2706. X        tmp = car(options);
  2707. X        
  2708. X        /* handle options that don't take arguments */
  2709. X        if (symbolp(tmp)) {
  2710. X        pname = (char *) getstring(getpname(tmp));
  2711. X        xlerror("unknown option",tmp);
  2712. X        }
  2713. X
  2714. X        /* handle options that take arguments */
  2715. X        else if (consp(tmp) && symbolp(car(tmp))) {
  2716. X        pname = (char *) getstring(getpname(car(tmp)));
  2717. X        oargs = cdr(tmp);
  2718. X
  2719. X        /* check for the :CONC-NAME keyword */
  2720. X        if (strcmp(pname,":CONC-NAME") == 0) {
  2721. X
  2722. X            /* get the name of the structure to include */
  2723. X            if (!consp(oargs) || !symbolp(car(oargs)))
  2724. X            xlerror("expecting a symbol",oargs);
  2725. X
  2726. X            /* save the prefix */
  2727. X            strcpy(prefix,getstring(getpname(car(oargs))));
  2728. X        }
  2729. X
  2730. X        /* check for the :INCLUDE keyword */
  2731. X        else if (strcmp(pname,":INCLUDE") == 0) {
  2732. X
  2733. X            /* get the name of the structure to include */
  2734. X            if (!consp(oargs) || !symbolp(car(oargs)))
  2735. X            xlerror("expecting a structure name",oargs);
  2736. X            tmp = car(oargs);
  2737. X            oargs = cdr(oargs);
  2738. X
  2739. X            /* add each slot from the included structure */
  2740. X            slots = xlgetprop(tmp,xlenter("*STRUCT-SLOTS*"));
  2741. X            for (; consp(slots); slots = cdr(slots)) {
  2742. X            if (consp(car(slots)) && consp(cdr(car(slots)))) {
  2743. X
  2744. X                /* get the next slot description */
  2745. X                tmp = car(slots);
  2746. X
  2747. X                /* create the slot access functions */
  2748. X                addslot(car(tmp),car(cdr(tmp)),++slotn,&args,&body);
  2749. X            }
  2750. X            }
  2751. X
  2752. X            /* handle slot initialization overrides */
  2753. X            for (; consp(oargs); oargs = cdr(oargs)) {
  2754. X            tmp = car(oargs);
  2755. X            if (symbolp(tmp)) {
  2756. X                slotname = tmp;
  2757. X                defexpr = NIL;
  2758. X            }
  2759. X            else if (consp(tmp) && symbolp(car(tmp))) {
  2760. X                slotname = car(tmp);
  2761. X                defexpr = (consp(cdr(tmp)) ? car(cdr(tmp)) : NIL);
  2762. X            }
  2763. X            else
  2764. X                xlerror("bad slot description",tmp);
  2765. X            updateslot(args,slotname,defexpr);
  2766. X            }
  2767. X        }
  2768. X        else
  2769. X            xlerror("unknown option",tmp);
  2770. X        }
  2771. X        else
  2772. X        xlerror("bad option syntax",tmp);
  2773. X    }
  2774. X    }
  2775. X
  2776. X    /* get each of the structure members */
  2777. X    while (moreargs()) {
  2778. X    
  2779. X    /* get the slot name and default value expression */
  2780. X    tmp = xlgetarg();
  2781. X    if (symbolp(tmp)) {
  2782. X        slotname = tmp;
  2783. X        defexpr = NIL;
  2784. X    }
  2785. X    else if (consp(tmp) && symbolp(car(tmp))) {
  2786. X        slotname = car(tmp);
  2787. X        defexpr = (consp(cdr(tmp)) ? car(cdr(tmp)) : NIL);
  2788. X    }
  2789. X    else
  2790. X        xlerror("bad slot description",tmp);
  2791. X    
  2792. X    /* create a closure for non-trival default expressions */
  2793. X    if (defexpr != NIL) {
  2794. X        tmp = newclosure(NIL,s_lambda,xlenv,xlfenv);
  2795. X        setbody(tmp,cons(defexpr,NIL));
  2796. X        tmp = cons(tmp,NIL);
  2797. X        defexpr = tmp;
  2798. X    }
  2799. X
  2800. X    /* create the slot access functions */
  2801. X    addslot(slotname,defexpr,++slotn,&args,&body);
  2802. X    }
  2803. X    
  2804. X    /* store the slotnames and default expressions */
  2805. X    xlputprop(structname,args,xlenter("*STRUCT-SLOTS*"));
  2806. X
  2807. X    /* enter the MAKE-xxx symbol */
  2808. X    sprintf(buf,"MAKE-%s",getstring(getpname(structname)));
  2809. X    sym = xlenter(buf);
  2810. X
  2811. X    /* make the MAKE-xxx function */
  2812. X    args = cons(lk_key,args);
  2813. X    tmp = cons(structname,NIL);
  2814. X    tmp = cons(s_quote,tmp);
  2815. X    body = cons(tmp,body);
  2816. X    body = cons(xlenter("%MAKE-STRUCT"),body);
  2817. X    body = cons(body,NIL);
  2818. X    setfunction(sym,
  2819. X        xlclose(sym,s_lambda,args,body,xlenv,xlfenv));
  2820. X
  2821. X    /* enter the xxx-P symbol */
  2822. X    sprintf(buf,"%s-P",getstring(getpname(structname)));
  2823. X    sym = xlenter(buf);
  2824. X
  2825. X    /* make the xxx-P function */
  2826. X    args = cons(xlenter("X"),NIL);
  2827. X    body = cons(xlenter("X"),NIL);
  2828. X    tmp = cons(structname,NIL);
  2829. X    tmp = cons(s_quote,tmp);
  2830. X    body = cons(tmp,body);
  2831. X    body = cons(xlenter("%STRUCT-TYPE-P"),body);
  2832. X    body = cons(body,NIL);
  2833. X    setfunction(sym,
  2834. X        xlclose(sym,s_lambda,args,body,NIL,NIL));
  2835. X
  2836. X    /* enter the COPY-xxx symbol */
  2837. X    sprintf(buf,"COPY-%s",getstring(getpname(structname)));
  2838. X    sym = xlenter(buf);
  2839. X
  2840. X    /* make the COPY-xxx function */
  2841. X    args = cons(xlenter("X"),NIL);
  2842. X    body = cons(xlenter("X"),NIL);
  2843. X    body = cons(xlenter("%COPY-STRUCT"),body);
  2844. X    body = cons(body,NIL);
  2845. X    setfunction(sym,
  2846. X        xlclose(sym,s_lambda,args,body,NIL,NIL));
  2847. X
  2848. X    /* restore the stack */
  2849. X    xlpopn(6);
  2850. X
  2851. X    /* return the structure name */
  2852. X    return (structname);
  2853. X}
  2854. X
  2855. X/* xlrdstruct - convert a list to a structure (used by the reader) */
  2856. XLVAL xlrdstruct(list)
  2857. X  LVAL list;
  2858. X{
  2859. X    LVAL structname,sym,slotname,expr,last,val;
  2860. X
  2861. X    /* protect the new structure */
  2862. X    xlsave1(expr);
  2863. X
  2864. X    /* get the structure name */
  2865. X    if (!consp(list) || !symbolp(car(list)))
  2866. X    xlerror("bad structure initialization list",list);
  2867. X    structname = car(list);
  2868. X    list = cdr(list);
  2869. X
  2870. X    /* enter the MAKE-xxx symbol */
  2871. X    sprintf(buf,"MAKE-%s",getstring(getpname(structname)));
  2872. X
  2873. X    /* initialize the MAKE-xxx function call expression */
  2874. X    expr = cons(xlenter(buf),NIL);
  2875. X    last = expr;
  2876. X
  2877. X    /* turn the rest of the initialization list into keyword arguments */
  2878. X    while (consp(list) && consp(cdr(list))) {
  2879. X
  2880. X    /* get the slot keyword name */
  2881. X    slotname = car(list);
  2882. X    if (!symbolp(slotname))
  2883. X        xlerror("expecting a slot name",slotname);
  2884. X    sprintf(buf,":%s",getstring(getpname(slotname)));
  2885. X
  2886. X    /* add the slot keyword */
  2887. X    rplacd(last,cons(xlenter(buf),NIL));
  2888. X    last = cdr(last);
  2889. X    list = cdr(list);
  2890. X
  2891. X    /* add the value expression */
  2892. X    rplacd(last,cons(car(list),NIL));
  2893. X    last = cdr(last);
  2894. X    list = cdr(list);
  2895. X    }
  2896. X
  2897. X    /* make sure all of the initializers were used */
  2898. X    if (consp(list))
  2899. X    xlerror("bad structure initialization list",list);
  2900. X
  2901. X    /* invoke the creation function */
  2902. X    val = xleval(expr);
  2903. X
  2904. X    /* restore the stack */
  2905. X    xlpop();
  2906. X
  2907. X    /* return the new structure */
  2908. X    return (val);
  2909. X}
  2910. X
  2911. X/* xlprstruct - print a structure (used by printer) */
  2912. Xxlprstruct(fptr,vptr,flag)
  2913. X  LVAL fptr,vptr; int flag;
  2914. X{
  2915. X    LVAL next;
  2916. X    int i,n;
  2917. X    xlputc(fptr,'#'); xlputc(fptr,'S'); xlputc(fptr,'(');
  2918. X    xlprint(fptr,getelement(vptr,0),flag);
  2919. X    next = xlgetprop(getelement(vptr,0),xlenter("*STRUCT-SLOTS*"));
  2920. X    for (i = 1, n = getsz(vptr) - 1; i <= n && consp(next); ++i) {
  2921. X    if (consp(car(next))) { /* should always succeed */
  2922. X        xlputc(fptr,' ');
  2923. X        xlprint(fptr,car(car(next)),flag);
  2924. X        xlputc(fptr,' ');
  2925. X        xlprint(fptr,getelement(vptr,i),flag);
  2926. X    }
  2927. X    next = cdr(next);
  2928. X    }
  2929. X    xlputc(fptr,')');
  2930. X}
  2931. X
  2932. X/* addslot - make the slot access functions */
  2933. XLOCAL addslot(slotname,defexpr,slotn,pargs,pbody)
  2934. X  LVAL slotname,defexpr; int slotn; LVAL *pargs,*pbody;
  2935. X{
  2936. X    LVAL sym,args,body,tmp;
  2937. X    
  2938. X    /* protect some pointers */
  2939. X    xlstkcheck(4);
  2940. X    xlsave(sym);
  2941. X    xlsave(args);
  2942. X    xlsave(body);
  2943. X    xlsave(tmp);
  2944. X    
  2945. X    /* construct the update function name */
  2946. X    sprintf(buf,"%s%s",prefix,getstring(getpname(slotname)));
  2947. X    sym = xlenter(buf);
  2948. X    
  2949. X    /* make the access function */
  2950. X    args = cons(xlenter("S"),NIL);
  2951. X    body = cons(cvfixnum((FIXTYPE)slotn),NIL);
  2952. X    body = cons(xlenter("S"),body);
  2953. X    body = cons(xlenter("%STRUCT-REF"),body);
  2954. X    body = cons(body,NIL);
  2955. X    setfunction(sym,
  2956. X        xlclose(sym,s_lambda,args,body,NIL,NIL));
  2957. X
  2958. X    /* make the update function */
  2959. X    args = cons(xlenter("V"),NIL);
  2960. X    args = cons(xlenter("S"),args);
  2961. X    body = cons(xlenter("V"),NIL);
  2962. X    body = cons(cvfixnum((FIXTYPE)slotn),body);
  2963. X    body = cons(xlenter("S"),body);
  2964. X    body = cons(xlenter("%STRUCT-SET"),body);
  2965. X    body = cons(body,NIL);
  2966. X    xlputprop(sym,
  2967. X          xlclose(NIL,s_lambda,args,body,NIL,NIL),
  2968. X          xlenter("*SETF*"));
  2969. X
  2970. X    /* add the slotname to the make-xxx keyword list */
  2971. X    tmp = cons(defexpr,NIL);
  2972. X    tmp = cons(slotname,tmp);
  2973. X    tmp = cons(tmp,NIL);
  2974. X    if ((args = *pargs) == NIL)
  2975. X    *pargs = tmp;
  2976. X    else {
  2977. X    while (cdr(args) != NIL)
  2978. X        args = cdr(args);
  2979. X    rplacd(args,tmp);
  2980. X    }
  2981. X    
  2982. X    /* add the slotname to the %make-xxx argument list */
  2983. X    tmp = cons(slotname,NIL);
  2984. X    if ((body = *pbody) == NIL)
  2985. X    *pbody = tmp;
  2986. X    else {
  2987. X    while (cdr(body) != NIL)
  2988. X        body = cdr(body);
  2989. X    rplacd(body,tmp);
  2990. X    }
  2991. X
  2992. X    /* restore the stack */
  2993. X    xlpopn(4);
  2994. X}
  2995. X
  2996. X/* updateslot - update a slot definition */
  2997. XLOCAL updateslot(args,slotname,defexpr)
  2998. X  LVAL args,slotname,defexpr;
  2999. X{
  3000. X    LVAL tmp;
  3001. X    for (; consp(args); args = cdr(args))
  3002. X    if (slotname == car(car(args))) {
  3003. X        if (defexpr != NIL) {
  3004. X        xlsave1(tmp);
  3005. X        tmp = newclosure(NIL,s_lambda,xlenv,xlfenv);
  3006. X        setbody(tmp,cons(defexpr,NIL));
  3007. X        tmp = cons(tmp,NIL);
  3008. X        defexpr = tmp;
  3009. X        xlpop();
  3010. X        }
  3011. X        rplaca(cdr(car(args)),defexpr);
  3012. X        break;
  3013. X    }
  3014. X    if (args == NIL)
  3015. X    xlerror("unknown slot name",slotname);
  3016. X}
  3017. END_OF_FILE
  3018. if test 12885 -ne `wc -c <'src/xlisp/xcore/c/xlstruct.c'`; then
  3019.     echo shar: \"'src/xlisp/xcore/c/xlstruct.c'\" unpacked with wrong size!
  3020. fi
  3021. # end of 'src/xlisp/xcore/c/xlstruct.c'
  3022. fi
  3023. echo shar: End of archive 6 \(of 16\).
  3024. cp /dev/null ark6isdone
  3025. MISSING=""
  3026. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
  3027.     if test ! -f ark${I}isdone ; then
  3028.     MISSING="${MISSING} ${I}"
  3029.     fi
  3030. done
  3031. if test "${MISSING}" = "" ; then
  3032.     echo You have unpacked all 16 archives.
  3033.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  3034. else
  3035.     echo You still need to unpack the following archives:
  3036.     echo "        " ${MISSING}
  3037. fi
  3038. ##  End of shell archive.
  3039. exit 0
  3040.